Package com.google.gwt.core.shared
Class SerializableThrowable
- java.lang.Object
-
- java.lang.Throwable
-
- com.google.gwt.core.shared.SerializableThrowable
-
- All Implemented Interfaces:
java.io.Serializable
public final class SerializableThrowable extends java.lang.ThrowableA serializable copy of aThrowable, including its causes and stack trace. It overrides#toStringto mimic originalThrowable.toString()so thatThrowable.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.
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description SerializableThrowable(java.lang.String designatedType, java.lang.String message)Constructs a new SerializableThrowable with the specified detail message.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.ThrowablefillInStackTrace()static SerializableThrowablefromThrowable(java.lang.Throwable throwable)Create a newSerializableThrowablefrom a provided throwable and its causes recursively.java.lang.StringgetDesignatedType()Returns the designated throwable's type name.java.lang.ThrowablegetOriginalThrowable()Returns the original throwable that this serializable throwable is derived from.java.lang.ThrowableinitCause(java.lang.Throwable cause)Initializes the cause of this throwable.booleanisExactDesignatedTypeKnown()Returntrueif provided type name is the exact type of the throwable that is designated by this instance.voidsetDesignatedType(java.lang.String typeName, boolean isExactType)Sets the designated Throwable's type name.java.lang.StringtoString()
-
-
-
Method Detail
-
fromThrowable
public static SerializableThrowable fromThrowable(java.lang.Throwable throwable)
Create a newSerializableThrowablefrom a provided throwable and its causes recursively.- Returns:
- a new SerializableThrowable or the passed object itself if it is
nullor already a SerializableThrowable.
-
fillInStackTrace
public java.lang.Throwable fillInStackTrace()
- Overrides:
fillInStackTracein classjava.lang.Throwable
-
setDesignatedType
public void setDesignatedType(java.lang.String typeName, boolean isExactType)Sets the designated Throwable's type name.- Parameters:
typeName- the class name of the underlying designated throwable.isExactType-falseif provided type name is not the exact type.- See Also:
isExactDesignatedTypeKnown()
-
getDesignatedType
public java.lang.String getDesignatedType()
Returns the designated throwable's type name.- See Also:
isExactDesignatedTypeKnown()
-
isExactDesignatedTypeKnown
public boolean isExactDesignatedTypeKnown()
Returntrueif provided type name is the exact type of the throwable that is designated by this instance. This can returnfalseif the class metadata is not available in the runtime. In that casegetDesignatedType()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.
-
initCause
public java.lang.Throwable initCause(java.lang.Throwable cause)
Initializes the cause of this throwable.This method will convert the cause to
SerializableThrowableif it is not already.- Overrides:
initCausein classjava.lang.Throwable
-
getOriginalThrowable
public java.lang.Throwable getOriginalThrowable()
Returns the original throwable that this serializable throwable is derived from. Note that the original throwable is kept in a transient field; that is; it will not be transferred to server side. In that case this method will returnnull.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Throwable
-
-