Handy class for wrapping checked Exceptions with a root cause.
This time-honored technique is no longer necessary in Java 1.4, which
finally provides built-in support for exception nesting. Thus exceptions in
applications written to use Java 1.4 need not extend this class. To ease
migration, this class mirrors Java 1.4's nested exceptions as closely as possible.
Abstract to force the programmer to extend the class. getMessage
will include nested exception information; printStackTrace etc will
delegate to the wrapped exception, if any.
The similarity between this class and the NestedRuntimeException class is
unavoidable, as Java forces these two classes to have different superclasses
(ah, the inflexibility of concrete inheritance!).
As discussed in
Expert One-On-One J2EE Design and Development,
runtime exceptions are often a better alternative to checked exceptions.
However, all exceptions should preserve their stack trace, if caused by a
lower-level exception.
This time-honored technique is no longer necessary in Java 1.4, which finally provides built-in support for exception nesting. Thus exceptions in applications written to use Java 1.4 need not extend this class. To ease migration, this class mirrors Java 1.4's nested exceptions as closely as possible.
Abstract to force the programmer to extend the class.
getMessagewill include nested exception information;printStackTraceetc will delegate to the wrapped exception, if any.The similarity between this class and the NestedRuntimeException class is unavoidable, as Java forces these two classes to have different superclasses (ah, the inflexibility of concrete inheritance!).
As discussed in Expert One-On-One J2EE Design and Development, runtime exceptions are often a better alternative to checked exceptions. However, all exceptions should preserve their stack trace, if caused by a lower-level exception.