Package gw.util
Class GosuExceptionUtil
java.lang.Object
gw.util.GosuExceptionUtil
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final LockingLazyVar<GosuExceptionUtil.IForceThrower>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Throwable>
TaddContextInfo
(T t, String ctxInfo) static <T extends Throwable>
TaddContextInfoImpl
(T t, String ctxInfo) private static boolean
areFilesEquals
(StackTraceElement throwableElt, StackTraceElement currentElt) private static boolean
areMethodsEquals
(StackTraceElement throwableElt, StackTraceElement currentElt) static RuntimeException
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
Given an Exception, finds the root cause and returns it.static RuntimeException
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
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.
-
Field Details
-
FORCE_THROWER
-
-
Constructor Details
-
GosuExceptionUtil
public GosuExceptionUtil()
-
-
Method Details
-
findExceptionCause
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
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
-
getStackTraceAsString
-
forceThrow
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
-
addContextInfo
-
addContextInfoImpl
-
areMethodsEquals
private static boolean areMethodsEquals(StackTraceElement throwableElt, StackTraceElement currentElt) -
areFilesEquals
-