|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.lang.Throwable | +--java.lang.Exception | +--org.apache.commons.lang.exception.NestableException
The base class of all exceptions which can contain other exceptions.
It is intended to ease the debugging by carrying on the information
about the exception which was caught and provoked throwing the
current exception. Catching and rethrowing may occur multiple
times, and provided that all exceptions except the first one
are descendants of NestedException
, when the
exception is finally printed out using any of the
printStackTrace()
methods, the stack trace will contain
the information about all exceptions thrown and caught on
the way.
Running the following program
1 import org.apache.commons.lang.exception.NestableException; 2 3 public class Test { 4 public static void main( String[] args ) { 5 try { 6 a(); 7 } catch(Exception e) { 8 e.printStackTrace(); 9 } 10 } 11 12 public static void a() throws Exception { 13 try { 14 b(); 15 } catch(Exception e) { 16 throw new NestableException("foo", e); 17 } 18 } 19 20 public static void b() throws Exception { 21 try { 22 c(); 23 } catch(Exception e) { 24 throw new NestableException("bar", e); 25 } 26 } 27 28 public static void c() throws Exception { 29 throw new Exception("baz"); 30 } 31 }
Yields the following stack trace:
org.apache.commons.lang.exception.NestableException: foo at Test.a(Test.java:16) at Test.main(Test.java:6) Caused by: org.apache.commons.lang.exception.NestableException: bar at Test.b(Test.java:24) at Test.a(Test.java:14) ... 1 more Caused by: java.lang.Exception: baz at Test.c(Test.java:29) at Test.b(Test.java:22) ... 2 more
Field Summary | |
protected NestableDelegate |
delegate
The helper instance which contains much of the code which we delegate to. |
Constructor Summary | |
NestableException()
Constructs a new NestableException without specified
detail message. |
|
NestableException(String msg)
Constructs a new NestableException with specified
detail message. |
|
NestableException(String msg,
Throwable cause)
Constructs a new NestableException with specified
detail message and nested Throwable . |
|
NestableException(Throwable cause)
Constructs a new NestableException with specified
nested Throwable . |
Method Summary | |
Throwable |
getCause()
{@inheritDoc} |
String |
getMessage()
Returns the detail message string of this throwable. |
String |
getMessage(int index)
{@inheritDoc} |
String[] |
getMessages()
{@inheritDoc} |
Throwable |
getThrowable(int index)
{@inheritDoc} |
int |
getThrowableCount()
{@inheritDoc} |
Throwable[] |
getThrowables()
{@inheritDoc} |
int |
indexOfThrowable(Class type)
{@inheritDoc} |
int |
indexOfThrowable(Class type,
int fromIndex)
{@inheritDoc} |
void |
printPartialStackTrace(PrintWriter out)
{@inheritDoc} |
void |
printStackTrace()
{@inheritDoc} |
void |
printStackTrace(PrintStream out)
{@inheritDoc} |
void |
printStackTrace(PrintWriter out)
{@inheritDoc} |
Methods inherited from class java.lang.Throwable |
fillInStackTrace, getLocalizedMessage, toString |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected NestableDelegate delegate
Constructor Detail |
public NestableException()
NestableException
without specified
detail message.public NestableException(String msg)
NestableException
with specified
detail message.msg
- The error message.public NestableException(Throwable cause)
NestableException
with specified
nested Throwable
.cause
- the exception or error that caused this exception to be
thrownpublic NestableException(String msg, Throwable cause)
NestableException
with specified
detail message and nested Throwable
.msg
- the error messagecause
- the exception or error that caused this exception to be
thrownMethod Detail |
public Throwable getCause()
getCause
in interface Nestable
org.apache.commons.lang.exception.Nestable
public String getMessage()
getMessage
in interface Nestable
getMessage
in class Throwable
public String getMessage(int index)
getMessage
in interface Nestable
org.apache.commons.lang.exception.Nestable
index
- the index of the Throwable
in the chain of
Throwable
sThrowable
at the
specified index in the chain does not contain a messageIndexOutOfBoundsException
- if the index
argument is
negative or not less than the count of Throwable
s in the
chainpublic String[] getMessages()
getMessages
in interface Nestable
org.apache.commons.lang.exception.Nestable
public Throwable getThrowable(int index)
getThrowable
in interface Nestable
org.apache.commons.lang.exception.Nestable
index
- the index, numbered from 0, of the Throwable
in
the chain of Throwable
sThrowable
IndexOutOfBoundsException
- if the index
argument is
negative or not less than the count of Throwable
s in the
chainpublic int getThrowableCount()
getThrowableCount
in interface Nestable
org.apache.commons.lang.exception.Nestable
public Throwable[] getThrowables()
getThrowables
in interface Nestable
org.apache.commons.lang.exception.Nestable
Throwable
spublic int indexOfThrowable(Class type)
indexOfThrowable
in interface Nestable
org.apache.commons.lang.exception.Nestable
type
- the type to find, subclasses match, null returns -1public int indexOfThrowable(Class type, int fromIndex)
indexOfThrowable
in interface Nestable
org.apache.commons.lang.exception.Nestable
type
- the type to find, subclasses match, null returns -1fromIndex
- the index, numbered from 0, of the starting position in
the chain to be searchedIndexOutOfBoundsException
- if the fromIndex
argument
is negative or not less than the count of Throwable
s in the
chainpublic void printStackTrace()
printStackTrace
in class Throwable
public void printStackTrace(PrintStream out)
printStackTrace
in interface Nestable
printStackTrace
in class Throwable
org.apache.commons.lang.exception.Nestable
out
- PrintStream
to use for output.public void printStackTrace(PrintWriter out)
printStackTrace
in interface Nestable
printStackTrace
in class Throwable
org.apache.commons.lang.exception.Nestable
out
- PrintWriter
to use for output.public final void printPartialStackTrace(PrintWriter out)
printPartialStackTrace
in interface Nestable
org.apache.commons.lang.exception.Nestable
out
- The writer to use.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |