public final class SerializableThrowable extends Throwable
Throwable
, including its causes and stack trace. It overrides
#toString
to mimic original Throwable.toString()
so that Throwable.printStackTrace()
will work as if it is coming from the original exception.
This class is especially useful for logging and testing as the emulated Throwable class does not serialize recursively and does not serialize the stack trace. This class, as an alternative, can be used to transfer the Throwable without losing any of these data, even if the underlying Throwable is not serializable.
Please note that, to get more useful stack traces from client side, this class needs to be used
in conjunction with StackTraceDeobfuscator
.
NOTE: Does not serialize suppressed exceptions to remain compatible with Java 6 and below.
Constructor and Description |
---|
SerializableThrowable(String designatedType,
String message)
Constructs a new SerializableThrowable with the specified detail message.
|
Modifier and Type | Method and Description |
---|---|
Throwable |
fillInStackTrace()
Populates the stack trace information for the Throwable.
|
static SerializableThrowable |
fromThrowable(Throwable throwable)
Create a new
SerializableThrowable from a provided throwable and its causes
recursively. |
String |
getDesignatedType()
Returns the designated throwable's type name.
|
Throwable |
getOriginalThrowable()
Returns the original throwable that this serializable throwable is derived from.
|
Throwable |
initCause(Throwable cause)
Initializes the cause of this throwable.
|
boolean |
isExactDesignatedTypeKnown()
Return
true if provided type name is the exact type of the throwable that is designated
by this instance. |
void |
setDesignatedType(String typeName,
boolean isExactType)
Sets the designated Throwable's type name.
|
String |
toString() |
addSuppressed, getBackingJsObject, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, of, printStackTrace, printStackTrace, setStackTrace
public static SerializableThrowable fromThrowable(Throwable throwable)
SerializableThrowable
from a provided throwable and its causes
recursively.null
or
already a SerializableThrowable.public Throwable fillInStackTrace()
Throwable
fillInStackTrace
in class Throwable
public void setDesignatedType(String typeName, boolean isExactType)
typeName
- the class name of the underlying designated throwable.isExactType
- false
if provided type name is not the exact type.isExactDesignatedTypeKnown()
public String getDesignatedType()
isExactDesignatedTypeKnown()
public boolean isExactDesignatedTypeKnown()
true
if provided type name is the exact type of the throwable that is designated
by this instance. This can return false
if the class metadata is not available in the
runtime. In that case getDesignatedType()
will return the type resolved by best-effort
and may not be the exact type; instead it can be one of the ancestors of the real type that
this instance designates.public Throwable initCause(Throwable cause)
This method will convert the cause to SerializableThrowable
if it is not already.
public Throwable getOriginalThrowable()
null
.Copyright © 2018. All rights reserved.