public abstract class AbstractRuntimeException extends java.lang.RuntimeException implements ICodedException, IThrowableWrapper
This unchecked exception class is designed as a base/expansion point for the entire hierarchy of unchecked exceptions in a project.
It provides the following features:
AbstractException
for a checked version of the same class.
TODO: javadoc
Each constructor that accepts a String 'message' parameter accepts an error
code as well. You are then responsible for ensuring that either the root
com.vladium.exception.exceptions
resource bundle
or your project/exception class-specific resource bundle [see
below for details] contains a mapping for this error
code. When this lookup fails the passed String value itself will be used as
the error message.
All constructors taking an 'arguments' parameter supply parameters to the error message used as a java.text.MessageFormat pattern.
Example:
File file = ...
try
...
catch (Exception e)
{
throw new AbstractRuntimeException ("FILE_NOT_FOUND", new Object[] {file, e}, e);
}
where com.vladium.util.exception.exceptions
contains:
FILE_NOT_FOUND: file {0} could not be opened: {1}
To log exception data use getMessage()
or printStackTrace
family of methods. You should never have to use toString().
It is also possible to use project- or exception
subhierarchy-specific message resource bundles without maintaining all error
codes in com.vladium.exception.exceptions
. To do so, create a
custom resource bundle and add the following static initializer code to your
base exception class:
The bundle name is relative to MyException package. This step can omitted if
the bundle name is "exceptions".
Note that the implementation correctly resolves error code name collisions
across independently developed exception families, as long as resource bundles
use unique names. Specifically, error codes follow inheritance and hiding rules
similar to Java class static methods. See
static
{
addExceptionResource (MyException.class, "my_custom_resource_bundle");
}
ExceptionCommon.addExceptionResource(java.lang.Class, java.lang.String)
for further details.
Modifier and Type | Field and Description |
---|---|
private java.lang.Object[] |
m_arguments |
private java.lang.Throwable |
m_cause |
private java.lang.String |
m_message |
Constructor and Description |
---|
AbstractRuntimeException()
Constructs an exception with null message and null cause.
|
AbstractRuntimeException(java.lang.String message)
Constructs an exception with given error message/code and null cause.
|
AbstractRuntimeException(java.lang.String message,
java.lang.Object[] arguments)
Constructs an exception with given error message/code and null cause.
|
AbstractRuntimeException(java.lang.String message,
java.lang.Object[] arguments,
java.lang.Throwable cause)
Constructs an exception with given error message/code and given cause.
|
AbstractRuntimeException(java.lang.String message,
java.lang.Throwable cause)
Constructs an exception with given error message/code and given cause.
|
AbstractRuntimeException(java.lang.Throwable cause)
Constructs an exception with null error message/code and given cause.
|
Modifier and Type | Method and Description |
---|---|
void |
__printStackTrace(java.io.PrintStream ps)
Every exception hierarchy implementing this interface must ensure that
this method delegates to super.printStackTrace(ps) where 'super' is the
first superclass not implementing IThrowableWrapper.
|
void |
__printStackTrace(java.io.PrintWriter pw)
Every exception hierarchy implementing this interface must ensure that
this method delegates to super.printStackTrace(pw) where 'super' is the
first superclass not implementing IThrowableWrapper.
|
static void |
addExceptionResource(java.lang.Class namespace,
java.lang.String messageResourceBundleName)
Equivalent to
ExceptionCommon.addExceptionResource(java.lang.Class, java.lang.String) , repeated here for
convenience. |
java.lang.Throwable |
getCause()
This implements
IThrowableWrapper
and also overrides the base method in JDK 1.4+. |
java.lang.String |
getErrorCode()
Returns the String that was passed as 'message' constructor argument.
|
java.lang.String |
getLocalizedMessage()
Overrides base method for the sole purpose of making it final.
|
java.lang.String |
getMessage()
Overrides base method to support error code lookup and avoid returning nulls.
|
void |
printStackTrace()
Overrides Exception.printStackTrace() to (a) force the output to go
to System.out and (b) handle nested exceptions in JDKs prior to 1.4.
|
void |
printStackTrace(java.io.PrintStream s)
Overrides Exception.printStackTrace() to handle nested exceptions in JDKs prior to 1.4.
|
void |
printStackTrace(java.io.PrintWriter s)
Overrides Exception.printStackTrace() to handle nested exceptions in JDKs prior to 1.4.
|
private void |
writeObject(java.io.ObjectOutputStream out) |
private java.lang.String m_message
private final transient java.lang.Object[] m_arguments
private final java.lang.Throwable m_cause
public AbstractRuntimeException()
public AbstractRuntimeException(java.lang.String message)
message
- the detail message [can be null]public AbstractRuntimeException(java.lang.String message, java.lang.Object[] arguments)
message
- the detail message [can be null]arguments
- message format parameters [can be null or empty]MessageFormat
public AbstractRuntimeException(java.lang.Throwable cause)
cause
- the cause [nested exception] [can be null]public AbstractRuntimeException(java.lang.String message, java.lang.Throwable cause)
message
- the detail message [can be null]cause
- the cause [nested exception] [can be null]public AbstractRuntimeException(java.lang.String message, java.lang.Object[] arguments, java.lang.Throwable cause)
message
- the detail message [can be null]arguments
- message format parameters [can be null or empty]cause
- the cause [nested exception] [can be null]MessageFormat
public final java.lang.String getMessage()
Equivalent to getLocalizedMessage()
.
getMessage
in class java.lang.Throwable
public final java.lang.String getLocalizedMessage()
Equivalent to getMessage()
.
getLocalizedMessage
in class java.lang.Throwable
public final void printStackTrace()
Subclasses cannot override.
printStackTrace
in class java.lang.Throwable
public final void printStackTrace(java.io.PrintStream s)
Subclasses cannot override.
printStackTrace
in class java.lang.Throwable
public final void printStackTrace(java.io.PrintWriter s)
Subclasses cannot override.
printStackTrace
in class java.lang.Throwable
public final java.lang.String getErrorCode()
getErrorCode
in interface ICodedException
public final java.lang.Throwable getCause()
IThrowableWrapper
and also overrides the base method in JDK 1.4+.getCause
in interface IThrowableWrapper
getCause
in class java.lang.Throwable
public void __printStackTrace(java.io.PrintStream ps)
IThrowableWrapper
ExceptionCommon
to avoid infinite
recursion and is not meant to be called by other classes.__printStackTrace
in interface IThrowableWrapper
public void __printStackTrace(java.io.PrintWriter pw)
IThrowableWrapper
ExceptionCommon
to avoid infinite
recursion and is not meant to be called by other classes.__printStackTrace
in interface IThrowableWrapper
public static void addExceptionResource(java.lang.Class namespace, java.lang.String messageResourceBundleName)
ExceptionCommon.addExceptionResource(java.lang.Class, java.lang.String)
, repeated here for
convenience. Subclasses should invoke from static initializers only.
'namespace' should be YourException.class.private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException
java.io.IOException