|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.lang.Throwable
java.lang.Exception
org.openmdx.kernel.exception.BasicException
public class BasicException
The StackedException implements stackable exceptions. Stackable exceptions are useful to avoid hidden exceptions and to allow for remapping exceptions while keeping the complete exception stack.
Instead of defining a central resource defining error codes the
StackedException follows the approach of a decentralized error
code management using error domains. An organization may define as many error
domains as required. Each error domain defines it's own error codes as
positive values starting with the value of '1'. An error code itself is not
unique, uniqness is only achieved together with an error domain.
To simplify things a number of common error codes are defined that are
are shared within all error domains. These error codes have negative values.
The StackedException provides error code mappers to map error
codes from foreign domains to strings. This mappers are used when requesting
a stringified form of the exception.
To enable interoperation with application domain specific exceptions
exception mappers are used to convert foreign exceptions to stacked
exceptions. These mappers are implicitely called when creating a new
StackedException passing an embedded exception that is not
of type StackedException.
A sample demonstrating the application of exception mappers in Corba applications:
Corba Server Corba Client
----------------------------------- -----------------------------------
: :
1) throw StackedException
2) convert to Corba User Exception
3) throw Corba User Exception
4) catch Corba User Exception
5) create StackedException passing
the Corba Exception -> invokes
the Corba Exception mapper
6) throw StackException
: :
Each StackedException provides several information elements:
Do not make subclasses: BasicException will be final as soon as the deprecated package org.openmdx.compatibility.base.exception has been removed!
| Nested Class Summary | |
|---|---|
static class |
BasicException.Code
|
static interface |
BasicException.Mapper
An Mapper implementation maps foreign exceptions to
BasicExceptions. |
static class |
BasicException.Parameter
The Parameter class represents a name-value pair. |
static interface |
BasicException.Wrapper
The interface Wrapper defines an exception as a wrapping
exception that wraps a cause (a BasicException) |
| Field Summary | |
|---|---|
static boolean |
isMicrosoftVM
The isMicrosoftVM property is set to true if the
currently active Java VM is a Microsoft Java VM. |
| Constructor Summary | |
|---|---|
BasicException(String exceptionDomain,
int exceptionCode,
BasicException.Parameter[] parameters,
String description)
Creates a new BasicException. |
|
BasicException(String className,
String methodName,
int lineNr,
String exceptionDomain,
int exceptionCode,
BasicException.Parameter[] parameters,
String description,
String[] callStack,
Date timestamp)
Creates a new BasicException. |
|
BasicException(Throwable throwable,
String exceptionDomain,
int exceptionCode,
BasicException.Parameter[] parameters,
String description)
Creates a new BasicException. |
|
BasicException(Throwable throwable,
String exceptionDomain,
int exceptionCode,
BasicException.Parameter[] parameters,
String description,
Throwable that)
Creates a new BasicException. |
|
BasicException(Throwable throwable,
String className,
String methodName,
int lineNr,
String exceptionDomain,
int exceptionCode,
BasicException.Parameter[] parameters,
String description,
String[] callStack,
Date timestamp)
Creates a new BasicException. |
|
| Method Summary | |
|---|---|
Throwable |
appendCause(Throwable throwable)
Appends the specified throwable to the end of the exception stack of this BasicException |
static List |
breakupDescription(String description)
Breaks up an exception description into simple text lines |
static String[] |
breakupStackTrace(Throwable throwable)
Breaks a stack trace of a throwable up into single entries, removes the leading 'at' and trims whitespaces. |
String[] |
getCallStack()
Retrieves the stack trace for this BasicException toplevel
object. |
Throwable |
getCause()
Returns the cause. |
BasicException |
getCause(String exceptionDomain)
Returns the cause belonging to a specific exception domain. |
String |
getClassName()
Retrieves the class for this BasicException object. |
String |
getDescription()
Retrieves the context for this BasicException toplevel
object. |
int |
getExceptionCode()
Retrieves the exception code for this BasicException
toplevel object. |
String |
getExceptionCodeString()
Retrieves the exception code for this BasicException
toplevel object. |
String |
getExceptionDomain()
Retrieves the domain for this BasicException toplevel
object. |
List |
getExceptionStack()
Returns the exception stack as a list of exceptions beginning with the first thrown exception. |
int |
getLineNr()
Retrieves the line number for this BasicException object. |
String |
getMethodName()
Retrieves the method for this BasicException object. |
String |
getParameter(String name)
Searches for the parameter with the specified name in the parameter list. |
BasicException.Parameter[] |
getParameters()
Retrieves the parameters for this BasicException toplevel
object. |
Date |
getTimestamp()
Retrieves the timestamp for this BasicException toplevel
object. |
Throwable |
initCause(Throwable throwable)
Initializes the cause of this throwable to the specified value. |
static HashMap |
parseStackTraceEntry(String[] stackTrace,
int index)
Parse a single stack trace line into its elements. |
void |
printStack(Throwable holder,
PrintStream stream,
boolean addBacktrace)
Prints the exception including all stacked exceptions to the specified print stream. |
void |
printStack(Throwable holder,
PrintWriter writer,
boolean addBacktrace)
Prints the exception including all stacked exceptions to the specified print writer. |
static void |
register(Class exClass,
BasicException.Mapper mapper)
Registers an exception mapper for a given exception class |
static void |
register(String exceptionDomain,
IntegerEnumeration.Mapper mapper)
Registers an error code mapper for a given exception domain |
static void |
setSource(Object source)
Set an exception source object. |
static BasicException |
toStackedException(Throwable throwable)
Maps a throwable to a BasicException using the registered
exception mappers |
static BasicException |
toStackedException(Throwable cause,
Throwable wrapper)
Create a BasicException representing a cause
wrapped into a wrapper. |
static BasicException |
toStackedException(Throwable cause,
Throwable wrapper,
BasicException.Parameter[] parameters)
Create a BasicException representing a cause
wrapped into a wrapper. |
String |
toString()
Returns a formatted multiline String representation for the exception including all stacked exceptions. |
String |
toString(boolean addBacktrace)
Returns a formatted multiline String representation for the exception including all stacked exceptions. |
String |
toStringTopLevel()
Returns a String representation for the exception's top level object. |
String |
toStringTopLevel(boolean addBacktrace)
Returns a String representation for the exception's top level object. |
| Methods inherited from class java.lang.Throwable |
|---|
fillInStackTrace, getLocalizedMessage, getMessage, getStackTrace, printStackTrace, printStackTrace, printStackTrace, setStackTrace |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final boolean isMicrosoftVM
isMicrosoftVM property is set to true if the
currently active Java VM is a Microsoft Java VM.
| Constructor Detail |
|---|
public BasicException(String exceptionDomain,
int exceptionCode,
BasicException.Parameter[] parameters,
String description)
BasicException.
exceptionDomain - An exception domain. A null objects references
the default exception domain with negative exception codes only.exceptionCode - An exception code. Negative codes describe common
exceptions codes. Positive exception codes are specific for a given
exception domain.parameters - Any exception parametersdescription - A readable description
public BasicException(Throwable throwable,
String exceptionDomain,
int exceptionCode,
BasicException.Parameter[] parameters,
String description)
BasicException.
throwable - An embedded exceptionexceptionDomain - An exception domain. A null objects references
the default exception domain with negative exception codes only.exceptionCode - An exception code. Negative codes describe common
exceptions codes. Positive exception codes are specific for a given
exception domain.parameters - Any exception parametersdescription - A readable description
public BasicException(String className,
String methodName,
int lineNr,
String exceptionDomain,
int exceptionCode,
BasicException.Parameter[] parameters,
String description,
String[] callStack,
Date timestamp)
BasicException.
This constructor is primarily used by exception mappers.
className - A class namemethodName - A method namelineNr - A line numberexceptionDomain - An exception domain. A null objects references
the default exception domain with negative exception codes only.exceptionCode - An exception code. Negative codes describe common
exceptions codes. Positive exception codes are specific for a given
exception domain.parameters - Any exception parametersdescription - A readable descriptioncallStack - timestamp -
public BasicException(Throwable throwable,
String className,
String methodName,
int lineNr,
String exceptionDomain,
int exceptionCode,
BasicException.Parameter[] parameters,
String description,
String[] callStack,
Date timestamp)
BasicException.
This constructor is primarily used by exception mappers.
throwable - An embedded exceptionclassName - A class namemethodName - A method namelineNr - A line numberexceptionDomain - An exception domain. A null objects references
the default exception domain with negative exception codes only.exceptionCode - An exception code. Negative codes describe common
exceptions codes. Positive exception codes are specific for a given
exception domain.parameters - Any exception parametersdescription - A readable descriptioncallStack - timestamp -
public BasicException(Throwable throwable,
String exceptionDomain,
int exceptionCode,
BasicException.Parameter[] parameters,
String description,
Throwable that)
BasicException.
This constructor is primarily used by exception mappers.
throwable - An embedded exceptionexceptionDomain - An exception domain. A null objects references
the default exception domain with negative exception codes only.exceptionCode - An exception code. Negative codes describe common
exceptions codes. Positive exception codes are specific for a given
exception domain.parameters - Any exception parametersdescription - A readable descriptionthat - A throwable from which the backtrace and other exception
information is used. If null this information is taken from the
this object.| Method Detail |
|---|
public Throwable getCause()
Added for JDK 1.4 compliancy.
getCause in class ThrowableBasicException
object.public Throwable initCause(Throwable throwable)
Added for JDK 1.4 compliancy.
initCause in class Throwablethrowable -
Throwable instance
IllegalArgumentException - if cause is this throwable.
(A throwable cannot be its own cause.)
IllegalStateException - if the cause has already been setpublic Throwable appendCause(Throwable throwable)
BasicException
throwable - A throwable to append
Throwable instancepublic static BasicException toStackedException(Throwable throwable)
BasicException using the registered
exception mappers
throwable -
public static BasicException toStackedException(Throwable cause,
Throwable wrapper)
BasicException representing a cause
wrapped into a wrapper.
cause - wrapper -
BasicException representing the cause
wrapped into wrapper
public static BasicException toStackedException(Throwable cause,
Throwable wrapper,
BasicException.Parameter[] parameters)
BasicException representing a cause
wrapped into a wrapper.
cause - wrapper -
BasicException representing the cause
wrapped into wrapperpublic String toStringTopLevel()
public String toStringTopLevel(boolean addBacktrace)
addBacktrace - if true add the exception's backtrace
public String toString()
toString in class Throwablepublic String toString(boolean addBacktrace)
addBacktrace - if true add the exception's backtrace
public void printStack(Throwable holder,
PrintStream stream,
boolean addBacktrace)
holder - stream - PrintStream to use for outputaddBacktrace - If true add the exception's backtrace
public void printStack(Throwable holder,
PrintWriter writer,
boolean addBacktrace)
holder - addBacktrace - If true add the exception's backtracestream - PrintWriter to use for outputpublic List getExceptionStack()
BasicException
objects.public String getParameter(String name)
public String getClassName()
BasicException object.
public String getMethodName()
BasicException object.
public int getLineNr()
BasicException object.
public String getExceptionDomain()
BasicException toplevel
object.
public int getExceptionCode()
BasicException
toplevel object.
public String getExceptionCodeString()
BasicException
toplevel object.
public Date getTimestamp()
BasicException toplevel
object.
public BasicException.Parameter[] getParameters()
BasicException toplevel
object.
public String getDescription()
BasicException toplevel
object.
public String[] getCallStack()
BasicException toplevel
object.
public static List breakupDescription(String description)
description - A descripion
public static void setSource(Object source)
Dynamic exception source example:
class ExceptionSource
{
public String toString()
{
return "ExceptionSource-" + System.currentTimeMillis();
}
}
BasicException.setSource(new ExceptionSource())
Static exception source example:
BasicException.setSource("ExceptionSource")
source - an exception source object
public static void register(String exceptionDomain,
IntegerEnumeration.Mapper mapper)
exceptionDomain - mapper -
public static void register(Class exClass,
BasicException.Mapper mapper)
exClass - mapper - public static String[] breakupStackTrace(Throwable throwable)
throwable -
public static HashMap parseStackTraceEntry(String[] stackTrace,
int index)
Elements:
stackTrace - index -
public BasicException getCause(String exceptionDomain)
exceptionDomain - the desired exception domain,
or null to retrieve the initial cause.
exceptionDomain is
null.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||