org.springframework.core
Class NestedRuntimeException

java.lang.Object
  |
  +--java.lang.Throwable
        |
        +--java.lang.Exception
              |
              +--java.lang.RuntimeException
                    |
                    +--org.springframework.core.NestedRuntimeException
Direct Known Subclasses:
AopConfigException, BeansException, DataAccessException, MailException, AttributeException, RemoteAccessException, TransactionException, VelocityInitializationException, FormatHelper.XsltFormattingException

public abstract class NestedRuntimeException
extends RuntimeException

Handy class for wrapping runtime Exceptions with a root cause. This time-honoured technique is no longer necessary in Java 1.4, which provides built-in support for exception nesting. Thus exceptions in applications written to use Java 1.4 need not extend this class.

Abstract to force the programmer to extend the class. printStackTrace() etc. are forwarded to the wrapped Exception. The present assumption is that all application-specific exceptions that could be displayed to humans (users, administrators etc.) will implement the ErrorCoded interface.

The similarity between this class and the NestedCheckedException 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.

Author:
Rod Johnson
Version: $Id: NestedRuntimeException.java,v 1.5 2004/02/02 11:38:33 jhoeller Exp $

Constructor Summary
NestedRuntimeException(String msg)
          Construct a ExceptionWrapperException with the specified detail message.
NestedRuntimeException(String msg, Throwable ex)
          Construct a RemoteException with the specified detail message and nested exception.

Method Summary
 ThrowablegetCause()
          Return the nested cause, or null if none.
 StringgetMessage()
          Return the detail message, including the message from the nested exception if there is one.
 voidprintStackTrace(PrintStream ps)
          Print the composite message and the embedded stack trace to the specified stream.
 voidprintStackTrace(PrintWriter pw)
          Print the composite message and the embedded stack trace to the specified writer.

Methods inherited from class java.lang.Throwable
printStackTrace, getStackTrace, setStackTrace, getLocalizedMessage, toString, fillInStackTrace, initCause

Methods inherited from class java.lang.Object
hashCode, notify, notifyAll, wait, wait, wait, getClass, equals

Constructor Detail

NestedRuntimeException

public NestedRuntimeException(String msg)
Construct a ExceptionWrapperException with the specified detail message.
Parameters:
msg - the detail message

NestedRuntimeException

public NestedRuntimeException(String msg, Throwable ex)
Construct a RemoteException with the specified detail message and nested exception.
Parameters:
msg - the detail message
ex - the nested exception
Method Detail

getCause

public Throwable getCause()
Return the nested cause, or null if none.

getMessage

public String getMessage()
Return the detail message, including the message from the nested exception if there is one.

printStackTrace

public void printStackTrace(PrintStream ps)
Print the composite message and the embedded stack trace to the specified stream.
Parameters:
ps - the print stream

printStackTrace

public void printStackTrace(PrintWriter pw)
Print the composite message and the embedded stack trace to the specified writer.
Parameters:
pw - the print writer

Association Links

to Class java.lang.Throwable

Root cause of this nested exception