Package org.apache.juneau.common.utils
Class ThrowableUtils
java.lang.Object
org.apache.juneau.common.utils.ThrowableUtils
Various utility methods for creating and working with throwables.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Interface used withUtils.safeSupplier(SupplierWithThrowable)
. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic RuntimeException
asRuntimeException
(Throwable cause) Creates a newRuntimeException
.static <T> T
Casts or wraps the specified throwable to the specified type.static <T extends Throwable>
TSame asThrowable.getCause()
but searches the throwable chain for an exception of the specified type.static String
Convenience method for getting a stack trace as a string.static int
Calculates a 16-bit hash for the specified throwable based on it's stack trace.
-
Constructor Details
-
ThrowableUtils
public ThrowableUtils()
-
-
Method Details
-
asRuntimeException
Creates a newRuntimeException
.- Parameters:
cause
- The caused-by exception.- Returns:
- A new
RuntimeException
, or the same exception if it's already of that type.
-
cast
Casts or wraps the specified throwable to the specified type.- Type Parameters:
T
- The class to cast to.- Parameters:
type
- The class to cast to.t
- The throwable to cast.- Returns:
- Either the same exception if it's already the specified type, or a wrapped exception.
-
getCause
Same asThrowable.getCause()
but searches the throwable chain for an exception of the specified type.- Type Parameters:
T
- The throwable type to search for.- Parameters:
c
- The throwable type to search for.t
- The throwable to search.- Returns:
- The exception, or
null if not found.
-
getStackTrace
Convenience method for getting a stack trace as a string.- Parameters:
t
- The throwable to get the stack trace from.- Returns:
- The same content that would normally be rendered via
t.printStackTrace()
-
hash
Calculates a 16-bit hash for the specified throwable based on it's stack trace.- Parameters:
t
- The throwable to calculate the stack trace on.stopClass
- Optional stop class on which to stop calculation of a stack trace beyond when found.- Returns:
- A calculated hash.
-