Package gw.util
Class GosuExceptionUtil
- java.lang.Object
-
- gw.util.GosuExceptionUtil
-
public class GosuExceptionUtil extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
GosuExceptionUtil.IForceThrower
-
Constructor Summary
Constructors Constructor Description GosuExceptionUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T extends Throwable>
TaddContextInfo(T t, String ctxInfo)
static <T extends Throwable>
TaddContextInfoImpl(T t, String ctxInfo)
static RuntimeException
convertToRuntimeException(Throwable t)
static <T extends Throwable>
TfindException(Class<T> exceptionTypeToFind, Throwable t)
Given an Exception and an Exception type to look for, finds the exception of that type or returns null if none of that type exist.static Throwable
findExceptionCause(Throwable e)
Given an Exception, finds the root cause and returns it.static RuntimeException
forceThrow(Throwable t)
This method will force the Throwable object that is passed in to be rethrown, regardless if it is a checked exception or not, allowing a developer to side step dealing with or wrapping checked exceptions in java.static RuntimeException
forceThrow(Throwable t, String ctxInfo)
static String
getStackTraceAsString(Throwable t)
static void
throwArgMismatchException(IllegalArgumentException exceptionToWrap, String featureName, Class[] actualParameters, Object[] args)
This method can be used to provide a more informative type-mismatch exception message than the standard java reflection does with its IllegalArgumentException.
-
-
-
Method Detail
-
findExceptionCause
public static Throwable findExceptionCause(Throwable e)
Given an Exception, finds the root cause and returns it. This may end up returning the originally passed exception if that was the root cause.- Parameters:
e
- the Throwable whose root cause should be located.- Returns:
- the root Throwable, or e if it is the root.
-
throwArgMismatchException
public static void throwArgMismatchException(IllegalArgumentException exceptionToWrap, String featureName, Class[] actualParameters, Object[] args)
This method can be used to provide a more informative type-mismatch exception message than the standard java reflection does with its IllegalArgumentException.- Parameters:
exceptionToWrap
- - exception to wrapfeatureName
- - feature being executed when the (e.g. "method" or "constructor")actualParameters
- - the actual parameter types expectedargs
- - the args passed to the feature
-
findException
public static <T extends Throwable> T findException(Class<T> exceptionTypeToFind, Throwable t)
Given an Exception and an Exception type to look for, finds the exception of that type or returns null if none of that type exist.
-
convertToRuntimeException
public static RuntimeException convertToRuntimeException(Throwable t)
-
forceThrow
public static RuntimeException forceThrow(Throwable t)
This method will force the Throwable object that is passed in to be rethrown, regardless if it is a checked exception or not, allowing a developer to side step dealing with or wrapping checked exceptions in java.
This method "returns" a RuntimeException, so that you don't have to put spurious return statements after it is called, but the method never exits normally, so the return value is never used.
An example usage would be:
throw GosuExceptionUtil.forceThrow( myCheckedException );
- Parameters:
t
- the throwable object to be rethrown.
-
forceThrow
public static RuntimeException forceThrow(Throwable t, String ctxInfo)
-
-