Package org.jppf.utils
Class ExceptionUtils
java.lang.Object
org.jppf.utils.ExceptionUtils
This class provides a set of utility methods for manipulating
Throwable objects.- Author:
- Laurent Cohen
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringGet the call stack for the current thread.static StringGet the message of the specifiedThrowablealong with its class name.static StringGet a throwable's stack trace.static ExceptiontoException(String message, Throwable throwable) Converts a generic Throwable into anException.static <E extends Exception>
EtoException(String message, Throwable throwable, Class<E> clazz) Converts a genericThrowableinto an Exception of the specified class.static ExceptiontoException(Throwable throwable) Converts a generic Throwable into an Exception.static <E extends Exception>
EtoException(Throwable throwable, Class<E> clazz) Converts a genericThrowableinto an Exception of the specified class.static RuntimeExceptiontoRuntimeException(String message, Throwable throwable) Converts a generic Throwable into aRuntimeException.static RuntimeExceptiontoRuntimeException(Throwable throwable) Converts a generic Throwable into aRuntimeException.
-
Method Details
-
getStackTrace
Get a throwable's stack trace.- Parameters:
t- the throwable to get the stack trace from.- Returns:
- the stack trace as a string.
-
getCallStack
Get the call stack for the current thread.- Returns:
- the call stack as a string.
-
getMessage
Get the message of the specifiedThrowablealong with its class name.- Parameters:
t- theThrowableobject from which to get the message.- Returns:
- a formatted message from the
Throwable.
-
toException
Converts a generic Throwable into an Exception. Ifthrowableis already an instance ofException, it is returned as is. -
toException
Converts a generic Throwable into anException. -
toRuntimeException
Converts a generic Throwable into aRuntimeException. Ifthrowableis already an instance ofRuntimeException, it is returned as is.- Parameters:
throwable- the Throwable to convert.- Returns:
- a (possibly new)
RuntimeExceptionwrapping theThrowableas its cause. - Since:
- 4.0
-
toRuntimeException
Converts a generic Throwable into aRuntimeException.- Parameters:
throwable- the Throwable to convert.message- the message of the xcreated exception.- Returns:
- a new
RuntimeExceptionwrapping theThrowableas its cause. - Since:
- 4.0
-
toException
Converts a genericThrowableinto an Exception of the specified class. Ifthrowableis already an instance of the specified exception class, it is returned as is.- Type Parameters:
E- the type of exception to return.- Parameters:
throwable- the Throwable to convert.clazz- the class of the exception to convert to.- Returns:
- a (possibly new) exception of the specified class wrapping the
Throwableas its cause, ornullif an exception of this class cannot be constructed. - Since:
- 4.0
-
toException
public static <E extends Exception> E toException(String message, Throwable throwable, Class<E> clazz) Converts a genericThrowableinto an Exception of the specified class.- Type Parameters:
E- the type of exception to return.- Parameters:
message- the message of the xcreated exception.throwable- the Throwable to convert.clazz- the class of the exception to convert to.- Returns:
- a new exception of the specified class wrapping the
Throwableas its cause, ornullif an exception of this class cannot be constructed. - Since:
- 4.0
-