public class NestedException
extends java.lang.Exception
NestedException defines a special Exception class that permits exceptions to wrap other exceptions. Much of the functionality of this class has been subsumed by the "chained exception" handling introduced in JDK 1.4. However, this class is retained for two reasons:
While NestedException can be used directly, it is most useful as a base class for other exceptions classes.
Constructor and Description |
---|
NestedException()
Default constructor, for an exception with no nested exception and
no message.
|
NestedException(java.lang.String message)
Constructs an exception containing an error message, but no
nested exception.
|
NestedException(java.lang.String bundleName,
java.lang.String messageKey,
java.lang.String defaultMsg)
Constructs an exception containing a resource bundle name, a message
key, and a default message (in case the resource bundle can't be
found).
|
NestedException(java.lang.String bundleName,
java.lang.String messageKey,
java.lang.String defaultMsg,
java.lang.Object[] msgParams)
Constructs an exception containing a resource bundle name, a message
key, a default message format (in case the resource bundle can't be
found), and arguments to be incorporated in the message via
java.text.MessageFormat.
|
NestedException(java.lang.String bundleName,
java.lang.String messageKey,
java.lang.String defaultMsg,
java.lang.Object[] msgParams,
java.lang.Throwable exception)
Constructs an exception containing a resource bundle name, a message
key, a default message format (in case the resource bundle can't be
found), arguments to be incorporated in the message via
java.text.MessageFormat, and another exception.
|
NestedException(java.lang.String bundleName,
java.lang.String messageKey,
java.lang.String defaultMsg,
java.lang.Throwable exception)
Constructs an exception containing a resource bundle name, a message
key, a default message (in case the resource bundle can't be found), and
another exception.
|
NestedException(java.lang.String message,
java.lang.Throwable exception)
Constructs an exception containing another exception and a message.
|
NestedException(java.lang.Throwable exception)
Constructs an exception containing another exception, but no message
of its own.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getMessage()
Returns the error message string for this exception.
|
java.lang.String |
getMessage(java.util.Locale locale)
Returns the error message string for this exception.
|
java.lang.String |
getMessages()
Get all the messages of all the nested exceptions, as one
string, with each message on a separate line.
|
java.lang.String |
getMessages(boolean elideNewlines)
Get all the messages of all the nested exceptions, as one string.
|
java.lang.String |
getMessages(boolean elideNewlines,
java.util.Locale locale)
Get all the messages of all the nested exceptions, as one string.
|
java.lang.Throwable |
getNestedException()
Deprecated.
Use java.lang.Throwable.getCause() instead
|
void |
printStackTrace()
Print a stack trace to standard error.
|
void |
printStackTrace(java.util.Locale locale)
Print a stack trace to standard error, using the specified locale.
|
void |
printStackTrace(java.io.PrintStream out)
Print a stack trace.
|
void |
printStackTrace(java.io.PrintStream out,
java.util.Locale locale)
Print a stack trace, using a specific locale for the output.
|
void |
printStackTrace(java.io.PrintWriter out)
Print a stack trace.
|
void |
printStackTrace(java.io.PrintWriter out,
java.util.Locale locale)
Print a stack trace, using a specific locale for the output.
|
java.lang.String |
toString()
Returns a short description of this exception.
|
public NestedException()
public NestedException(java.lang.Throwable exception)
exception
- the exception to containpublic NestedException(java.lang.String message)
message
- the message to associate with this exceptionpublic NestedException(java.lang.String message, java.lang.Throwable exception)
message
- the message to associate with this exceptionexception
- the exception to containpublic NestedException(java.lang.String bundleName, java.lang.String messageKey, java.lang.String defaultMsg)
NestedException(String,String,String,Object[])
constructor, with a null pointer for the Object[] parameter.
Calls to getMessage(Locale)
will attempt to retrieve
the top-most message (i.e., the message from this exception, not
from nested exceptions) by querying the named resource bundle.
Calls to printStackTrace(PrintWriter,Locale)
will do the same,
where applicable. The message is not retrieved until one of those
methods is called, because the desired locale is passed into
getMessage() and printStackTrace(), not this
constructor.bundleName
- resource bundle namemessageKey
- the key to the message to find in the bundledefaultMsg
- the default messageNestedException(String,String,String,Object[])
,
getMessage(Locale)
public NestedException(java.lang.String bundleName, java.lang.String messageKey, java.lang.String defaultMsg, java.lang.Object[] msgParams)
NestedException(String,String,String,Object[],Throwable)
with a null Throwable parameter. Calls to
getMessage(Locale)
will attempt to retrieve the top-most
message (i.e., the message from this exception, not from nested
exceptions) by querying the named resource bundle. Calls to
printStackTrace(PrintWriter,Locale)
will do the same, where
applicable. The message is not retrieved until one of those methods
is called, because the desired locale is passed into
getMessage() and printStackTrace(), not this
constructor.bundleName
- resource bundle namemessageKey
- the key to the message to find in the bundledefaultMsg
- the default messagemsgParams
- parameters to the message, if any, or nullNestedException(String,String,String,Object[])
,
getMessage(Locale)
public NestedException(java.lang.String bundleName, java.lang.String messageKey, java.lang.String defaultMsg, java.lang.Throwable exception)
NestedException(String,String,String,Object[],Throwable)
constructor, with a null pointer for the Object[]
parameter. Calls to getMessage(Locale)
will attempt to
retrieve the top-most message (i.e., the message from this
exception, not from nested exceptions) by querying the named
resource bundle. Calls to
printStackTrace(PrintWriter,Locale)
will do the same, where
applicable. The message is not retrieved until one of those methods
is called, because the desired locale is passed into
getMessage() and printStackTrace(), not this
constructor.bundleName
- resource bundle namemessageKey
- the key to the message to find in the bundledefaultMsg
- the default messageexception
- the exception to nestNestedException(String,String,String,Object[])
,
getMessage(Locale)
public NestedException(java.lang.String bundleName, java.lang.String messageKey, java.lang.String defaultMsg, java.lang.Object[] msgParams, java.lang.Throwable exception)
getMessage(Locale)
will attempt to retrieve the
top-most message (i.e., the message from this exception, not from
nested exceptions) by querying the named resource bundle. Calls to
printStackTrace(PrintWriter,Locale)
will do the same, where
applicable. The message is not retrieved until one of those methods
is called, because the desired locale is passed into
getMessage() and printStackTrace(), not this
constructor.bundleName
- resource bundle namemessageKey
- the key to the message to find in the bundledefaultMsg
- the default messagemsgParams
- parameters to the message, if any, or nullexception
- exception to be nestedNestedException(String,String,String,Object[])
,
getMessage(Locale)
public java.lang.String getMessage()
getMessage
in class java.lang.Throwable
public java.lang.String getMessage(java.util.Locale locale)
locale
- the locale to use, or null for the defaultpublic java.lang.String getMessages()
getMessages(boolean)
, with a
parameter of true.getMessages(boolean)
public java.lang.String getMessages(boolean elideNewlines)
elideNewlines
- whether to elide newlines or notpublic java.lang.String getMessages(boolean elideNewlines, java.util.Locale locale)
elideNewlines
- whether to elide newlines or notlocale
- the locale to use, or null for the defaultpublic java.lang.Throwable getNestedException()
public java.lang.String toString()
getMessage()
method for this object
toString
in class java.lang.Throwable
public void printStackTrace()
printStackTrace
in class java.lang.Throwable
printStackTrace(Locale)
,
printStackTrace(PrintWriter)
,
printStackTrace(PrintStream)
public void printStackTrace(java.util.Locale locale)
locale
- the locale to use, or null for the defaultprintStackTrace(Locale)
,
printStackTrace(PrintWriter)
,
printStackTrace(PrintStream)
public void printStackTrace(java.io.PrintWriter out)
printStackTrace
in class java.lang.Throwable
out
- where to dump the stack traceprintStackTrace()
,
printStackTrace(PrintWriter,Locale)
,
printStackTrace(PrintStream)
public void printStackTrace(java.io.PrintWriter out, java.util.Locale locale)
out
- where to dump the stack tracelocale
- the locale to use, or null for the defaultprintStackTrace()
,
printStackTrace(PrintWriter)
,
printStackTrace(PrintStream,Locale)
public void printStackTrace(java.io.PrintStream out)
printStackTrace
in class java.lang.Throwable
out
- where to dump the stack traceprintStackTrace()
,
printStackTrace(PrintStream,Locale)
,
printStackTrace(PrintWriter)
public void printStackTrace(java.io.PrintStream out, java.util.Locale locale)
out
- where to dump the stack tracelocale
- the locale to use, or null for the defaultprintStackTrace()
,
printStackTrace(PrintStream)
,
printStackTrace(PrintWriter,Locale)