|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.Throwable
java.lang.Exception
ExceptionWrapper
public class ExceptionWrapper
Serves as a base class for
s, to allow
exception nesting. Extend this class for your custom service exception case.
Alternately, if you don't like the constructors or methods of this exception,
implement WrappableException
to create your own -- it's
nesting behavior will be compatible with this class, allowing interchangable
nesting of either without clunky subclassing behavior.
WrappableException
Inside your service, catch low-level exceptions and re-throw them wrapped in
your custom exception. This allows simplification of clients who need to
catch exceptions from your service, but doesn't sacrifice the level of detail
represented by the wrapped exception, since it is accessible via
getEnclosedException()
.
For example, if you've created a custom "MyServiceException" that extends either this Exception, or, alternately, implements the WrapperableException interface, when using it the internals of your service might look like:
try { someOperationWhichThrowsAnException(); } catch (SomeLowLevelException ex) { throw new MyServiceException("Something jiggy is up while doing this!", ex); }A client, after catching "MyServiceException", can either extract the enclosed exception or call methods on this exception, like
toString()
,
to derive its internals and save them to a log, email them to a developer, or
display them to a user.
The exception classnames and messages are number 1 to N, from outermost to innermost. The innermost also has an appended call stack trace to allow pinpointing the source of the exception.
WrappableException
,
Serialized FormField Summary | |
---|---|
private java.lang.Exception |
nestedException
|
Constructor Summary | |
---|---|
ExceptionWrapper()
Constructs a ExceptionWrapper with no specific message. |
|
ExceptionWrapper(java.lang.Exception e)
Constructs an ExceptionWrapper with no specific message and wraps the specified Exception which caused the problem. |
|
ExceptionWrapper(java.lang.String desc)
Constructs an ExceptionWrapper with the specified message. |
|
ExceptionWrapper(java.lang.String desc,
java.lang.Exception e)
Constructs an ExceptionWrapper with the specified message and wraps the specified Exception which caused the problem. |
Method Summary | |
---|---|
protected static java.lang.String |
getClassName(java.lang.Object o)
Helper to get name of Class of the given Object. |
java.lang.Exception |
getEnclosedException()
Allow access to enclosed exception. |
protected static java.lang.String |
getStackTraceAsString(java.lang.Exception e)
Gets an exception's stack trace as a String :NOTE: this could be moved to a utils class |
void |
printStackTrace()
Overriden method from Throwable. |
void |
printStackTrace(java.io.PrintStream s)
Overriden method from Throwable. |
void |
printStackTrace(java.io.PrintWriter s)
Overriden method from Throwable. |
java.lang.String |
toString()
Allow access to messages and stack trace of this and any enclosed exception, including nested SQLExceptions. |
Methods inherited from class java.lang.Throwable |
---|
fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, initCause, setStackTrace |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private java.lang.Exception nestedException
Constructor Detail |
---|
public ExceptionWrapper()
public ExceptionWrapper(java.lang.String desc)
public ExceptionWrapper(java.lang.String desc, java.lang.Exception e)
desc
- a String
representing the description of the
problem that occurrede
- Exception
to be wrappedpublic ExceptionWrapper(java.lang.Exception e)
e
- Exception
which caused the problemMethod Detail |
---|
public java.lang.Exception getEnclosedException()
getEnclosedException
in interface WrappableException
Exception
, may be nullpublic java.lang.String toString()
toString
in class java.lang.Throwable
protected static java.lang.String getStackTraceAsString(java.lang.Exception e)
e
- the exception
protected static java.lang.String getClassName(java.lang.Object o)
o
- the Object to derive the class name from.
public void printStackTrace(java.io.PrintWriter s)
Throwable
.
printStackTrace
in class java.lang.Throwable
Throwable.printStackTrace(PrintWriter)
public void printStackTrace(java.io.PrintStream s)
WrappableException
s and prints
stacktrace of the wrapped exception. For details on this message see
Throwable
.
printStackTrace
in class java.lang.Throwable
Throwable.printStackTrace(PrintStream)
public void printStackTrace()
Throwable
.
printStackTrace
in class java.lang.Throwable
Throwable.printStackTrace()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |