|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
com.healthmarketscience.common.util.PassthroughException
public final class PassthroughException
This exception is useful for copying internal exceptions within one classloader so that they can be inspected within another classloader (after serialization/deserialization) without throwing ClassNotFoundException (or related exceptions). This is assuming, of course, that this class is available in both classloaders. An example for this would be an exception generated within a remote server, where the client code would not have the actual class of the exception. By "copying" the exception as a PassthroughException, the exception details can be "passed through" the classloader barrier. The receiver will get a complete stacktrace which looks identical to the server-side stacktrace without any of the class definition issues.
Example usage:
public class MyBean { public int computeSomething() throws MyPublicBeanException { try { // use some internal library to do something } catch(InternalImplException e) { throw new MyPublicBeanException("Failed doing something", PassthroughException.create(e)); } } }
Constructor Summary | |
---|---|
PassthroughException(String originalException,
String originalMessage,
StackTraceElement[] originalStackTrace,
PassthroughException cause)
Constructs a PassthroughException with the given information. |
|
PassthroughException(Throwable original,
PassthroughException cause)
Constructs a PassthroughException by copying information from the given original exception. |
Method Summary | ||
---|---|---|
static PassthroughException |
create(Throwable t)
Constructs a PassthroughException which will print out a virtually identical stacktrace to the given Throwable. |
|
static
|
create(Throwable t,
Class<ExType> exType,
String defaultMsg)
Creates an exception of the given type, with the given throwable translated to a PassthroughException as the cause. |
|
static
|
create(Throwable t,
Class<ExType> exType,
String defaultMsg,
boolean throwError)
Creates an exception of the given type, with the given throwable translated to a PassthroughException as the cause. |
|
String |
getOriginalExceptionName()
|
|
String |
toString()
|
Methods inherited from class java.lang.Throwable |
---|
fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public PassthroughException(Throwable original, PassthroughException cause)
original
- the original non-portable exceptioncause
- the cause for this exception, (most likely also a
PassthroughException)for simple instantiation of a PassthroughException
public PassthroughException(String originalException, String originalMessage, StackTraceElement[] originalStackTrace, PassthroughException cause)
originalException
- class name of the original exceptionoriginalMessage
- message of the original exceptionoriginalStackTrace
- stacktrace of the original exceptioncause
- the cause for this exception, (most likely also a
PassthroughException)for simple instantiation of a PassthroughException
Method Detail |
---|
public String toString()
toString
in class Throwable
public String getOriginalExceptionName()
public static PassthroughException create(Throwable t)
Note, if the given throwable is already a PassthroughException, it will be returned as-is.
t
- the throwable to deeply "copy".
null
if given null
.public static <ExType extends Throwable> ExType create(Throwable t, Class<ExType> exType, String defaultMsg)
This method will throw Errors immediately, as-is.
t
- throwable cause to wrap as a PassthroughExceptionexType
- the returned exception will be a subclass of this type.
This type (and it's subclasses) must have a public
constructor like ExType(String, Throwable)
.defaultMsg
- if the top exception is not of exType and this message
is non-null
, this will be the message of the
resulting exception, otherwise the message of the top
PassthroughException will be used (or ""
if
none).
null
if given null
.public static <ExType extends Throwable> ExType create(Throwable t, Class<ExType> exType, String defaultMsg, boolean throwError)
Errors may optionally be thrown immediately, as-is, or wrapped as any other cause.
t
- throwable cause to wrap as a PassthroughExceptionexType
- the returned exception will be a subclass of this type.
This type (and it's subclasses) must have a public
constructor like ExType(String, Throwable)
.defaultMsg
- if the top exception is not of exType and this message
is non-null
, this will be the message of the
resulting exception, otherwise the message of the top
PassthroughException will be used (or ""
if
none).throwError
- iff true
, Errors will be thrown immediately,
as-is, otherwise they will be treated like any other
cause.
null
if given null
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |