Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.commons.lang.exception
Class NestableException

    java.lang.Object
      |
      +--java.lang.Throwable
            |
            +--java.lang.Exception
                  |
                  +--org.apache.commons.lang.exception.NestableException

All Implemented Interfaces:
  Nestable, Serializable

public class NestableException
extends Exception
implements Nestable

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

Since:
  1.0
Version:
  $Id: NestableException.java 491651 2007-01-01 22:01:32Z ggregory $
Author:
  Rafal Krzewski, Daniel Rall, Kasper Nielsen, Steven Caswell
See Also:
  Serialized Form

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

### delegate

    protected NestableDelegate delegate

  The helper instance which contains much of the code which we delegate to.

Constructor Detail

### NestableException

    public NestableException()

  Constructs a new `NestableException` without specified detail message.

### NestableException

    public NestableException(String msg)

  Constructs a new `NestableException` with specified detail message.
  Parameters:
    `msg` - The error message.

### NestableException

    public NestableException(Throwable cause)

  Constructs a new `NestableException` with specified nested `Throwable`.
  Parameters:
    `cause` - the exception or error that caused this exception to be thrown

### NestableException

    public NestableException(String msg,
                             Throwable cause)

  Constructs a new `NestableException` with specified detail message and nested `Throwable`.
  Parameters:
    `msg` - the error message
    `cause` - the exception or error that caused this exception to be thrown

Method Detail

### getCause

    public Throwable getCause()

  {@inheritDoc}
  Specified by:
    `getCause` in interface `Nestable`
  Following copied from interface: `org.apache.commons.lang.exception.Nestable`
  Returns:
    throwable that caused the original exception

### getMessage

    public String getMessage()

  Returns the detail message string of this throwable. If it was created with a null message, returns the following: (cause==null ? null : cause.toString()).
  Specified by:
    `getMessage` in interface `Nestable`
  Overrides:
    `getMessage` in class `Throwable`
  Returns:
    String message string of the throwable

### getMessage

    public String getMessage(int index)

  {@inheritDoc}
  Specified by:
    `getMessage` in interface `Nestable`
  Following copied from interface: `org.apache.commons.lang.exception.Nestable`
  Parameters:
    `index` - the index of the `Throwable` in the chain of `Throwable`s
  Returns:
    the error message, or null if the `Throwable` at the specified index in the chain does not contain a message
  Throws:
    `IndexOutOfBoundsException` - if the `index` argument is negative or not less than the count of `Throwable`s in the chain

### getMessages

    public String[] getMessages()

  {@inheritDoc}
  Specified by:
    `getMessages` in interface `Nestable`
  Following copied from interface: `org.apache.commons.lang.exception.Nestable`
  Returns:
    the error messages

### getThrowable

    public Throwable getThrowable(int index)

  {@inheritDoc}
  Specified by:
    `getThrowable` in interface `Nestable`
  Following copied from interface: `org.apache.commons.lang.exception.Nestable`
  Parameters:
    `index` - the index, numbered from 0, of the `Throwable` in the chain of `Throwable`s
  Returns:
    the `Throwable`
  Throws:
    `IndexOutOfBoundsException` - if the `index` argument is negative or not less than the count of `Throwable`s in the chain

### getThrowableCount

    public int getThrowableCount()

  {@inheritDoc}
  Specified by:
    `getThrowableCount` in interface `Nestable`
  Following copied from interface: `org.apache.commons.lang.exception.Nestable`
  Returns:
    the throwable count

### getThrowables

    public Throwable[] getThrowables()

  {@inheritDoc}
  Specified by:
    `getThrowables` in interface `Nestable`
  Following copied from interface: `org.apache.commons.lang.exception.Nestable`
  Returns:
    the `Throwable`s

### indexOfThrowable

    public int indexOfThrowable(Class type)

  {@inheritDoc}
  Specified by:
    `indexOfThrowable` in interface `Nestable`
  Following copied from interface: `org.apache.commons.lang.exception.Nestable`
  Parameters:
    `type` - the type to find, subclasses match, null returns -1
  Returns:
    index of the first occurrence of the type in the chain, or -1 if the type is not found

### indexOfThrowable

    public int indexOfThrowable(Class type,
                                int fromIndex)

  {@inheritDoc}
  Specified by:
    `indexOfThrowable` in interface `Nestable`
  Following copied from interface: `org.apache.commons.lang.exception.Nestable`
  Parameters:
    `type` - the type to find, subclasses match, null returns -1
    `fromIndex` - the index, numbered from 0, of the starting position in the chain to be searched
  Returns:
    index of the first occurrence of the type in the chain, or -1 if the type is not found
  Throws:
    `IndexOutOfBoundsException` - if the `fromIndex` argument is negative or not less than the count of `Throwable`s in the chain

### printStackTrace

    public void printStackTrace()

  {@inheritDoc}
  Overrides:
    `printStackTrace` in class `Throwable`

### printStackTrace

    public void printStackTrace(PrintStream out)

  {@inheritDoc}
  Specified by:
    `printStackTrace` in interface `Nestable`
  Overrides:
    `printStackTrace` in class `Throwable`
  Following copied from interface: `org.apache.commons.lang.exception.Nestable`
  Parameters:
    `out` - `PrintStream` to use for output.

### printStackTrace

    public void printStackTrace(PrintWriter out)

  {@inheritDoc}
  Specified by:
    `printStackTrace` in interface `Nestable`
  Overrides:
    `printStackTrace` in class `Throwable`
  Following copied from interface: `org.apache.commons.lang.exception.Nestable`
  Parameters:
    `out` - `PrintWriter` to use for output.

### printPartialStackTrace

    public final void printPartialStackTrace(PrintWriter out)

  {@inheritDoc}
  Specified by:
    `printPartialStackTrace` in interface `Nestable`
  Following copied from interface: `org.apache.commons.lang.exception.Nestable`
  Parameters:
    `out` - The writer to use.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2001-2005 - Apache Software Foundation