Package gw.util
Class GosuExceptionUtil
- java.lang.Object
-
- gw.util.GosuExceptionUtil
-
public class GosuExceptionUtil extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceGosuExceptionUtil.IForceThrower
-
Field Summary
Fields Modifier and Type Field Description private static LockingLazyVar<GosuExceptionUtil.IForceThrower>FORCE_THROWER
-
Constructor Summary
Constructors Constructor Description GosuExceptionUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T extends java.lang.Throwable>
TaddContextInfo(T t, java.lang.String ctxInfo)static <T extends java.lang.Throwable>
TaddContextInfoImpl(T t, java.lang.String ctxInfo)private static booleanareFilesEquals(java.lang.StackTraceElement throwableElt, java.lang.StackTraceElement currentElt)private static booleanareMethodsEquals(java.lang.StackTraceElement throwableElt, java.lang.StackTraceElement currentElt)static java.lang.RuntimeExceptionconvertToRuntimeException(java.lang.Throwable t)static <T extends java.lang.Throwable>
TfindException(java.lang.Class<T> exceptionTypeToFind, java.lang.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 java.lang.ThrowablefindExceptionCause(java.lang.Throwable e)Given an Exception, finds the root cause and returns it.static java.lang.RuntimeExceptionforceThrow(java.lang.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 java.lang.RuntimeExceptionforceThrow(java.lang.Throwable t, java.lang.String ctxInfo)static java.lang.StringgetStackTraceAsString(java.lang.Throwable t)static voidthrowArgMismatchException(java.lang.IllegalArgumentException exceptionToWrap, java.lang.String featureName, java.lang.Class[] actualParameters, java.lang.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 Detail
-
FORCE_THROWER
private static final LockingLazyVar<GosuExceptionUtil.IForceThrower> FORCE_THROWER
-
-
Method Detail
-
findExceptionCause
public static java.lang.Throwable findExceptionCause(java.lang.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(java.lang.IllegalArgumentException exceptionToWrap, java.lang.String featureName, java.lang.Class[] actualParameters, java.lang.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 java.lang.Throwable> T findException(java.lang.Class<T> exceptionTypeToFind, java.lang.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 java.lang.RuntimeException convertToRuntimeException(java.lang.Throwable t)
-
getStackTraceAsString
public static java.lang.String getStackTraceAsString(java.lang.Throwable t)
-
forceThrow
public static java.lang.RuntimeException forceThrow(java.lang.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 java.lang.RuntimeException forceThrow(java.lang.Throwable t, java.lang.String ctxInfo)
-
addContextInfo
public static <T extends java.lang.Throwable> T addContextInfo(T t, java.lang.String ctxInfo)
-
addContextInfoImpl
public static <T extends java.lang.Throwable> T addContextInfoImpl(T t, java.lang.String ctxInfo)
-
areMethodsEquals
private static boolean areMethodsEquals(java.lang.StackTraceElement throwableElt, java.lang.StackTraceElement currentElt)
-
areFilesEquals
private static boolean areFilesEquals(java.lang.StackTraceElement throwableElt, java.lang.StackTraceElement currentElt)
-
-