public class GosuExceptionUtil extends Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
GosuExceptionUtil.IForceThrower |
| Constructor and Description |
|---|
GosuExceptionUtil() |
| Modifier and Type | Method and Description |
|---|---|
static <T extends Throwable> |
addContextInfo(T t,
String ctxInfo) |
static <T extends Throwable> |
addContextInfoImpl(T t,
String ctxInfo) |
static RuntimeException |
convertToRuntimeException(Throwable t) |
static <T extends Throwable> |
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.
|
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.
|
public static Throwable findExceptionCause(Throwable e)
e - the Throwable whose root cause should be located.public static void throwArgMismatchException(IllegalArgumentException exceptionToWrap, String featureName, Class[] actualParameters, Object[] args)
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 featurepublic static <T extends Throwable> T findException(Class<T> exceptionTypeToFind, Throwable t)
public static RuntimeException convertToRuntimeException(Throwable t)
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 );
t - the throwable object to be rethrown.public static RuntimeException forceThrow(Throwable t, String ctxInfo)
Copyright © 2021. All rights reserved.