org.openmdx.base.exception
Class ServiceException

java.lang.Object
  extended by java.lang.Throwable
      extended by java.lang.Exception
          extended by org.openmdx.base.exception.ServiceException
All Implemented Interfaces:
Serializable, BasicException.Wrapper, MultiLineStringRepresentation

public final class ServiceException
extends Exception
implements BasicException.Wrapper

See Also:
Serialized Form

Constructor Summary
ServiceException(BasicException exception)
          Constructor
ServiceException(Exception exception)
          Constructor
ServiceException(Exception cause, String exceptionDomain, int exceptionCode, BasicException.Parameter[] parameters, String description)
          Creates a new ServiceException.
ServiceException(String exceptionDomain, int exceptionCode, BasicException.Parameter[] parameters, String description)
          Creates a new ServiceException.
 
Method Summary
 ServiceException appendCause(Throwable cause)
           
 Throwable getCause()
          Returns the cause of an exception.
 BasicException getCause(String exceptionDomain)
          Returns the cause belonging to a specific exception domain.
 String getClassName()
          Deprecated. use @{link ServiceException#getStackedException()} followed by
 String getDescription()
          Deprecated. use @{link ServiceException#getStackedException()} followed by
 String getDomain()
          Deprecated. use @{link ServiceException#getExceptionDomain()}.
 int getErrorCode()
          Deprecated. use @{link ServiceException#getStackedException()} followed by
 int getExceptionCode()
          Retrieves the exception code of this ServiceException.
 String getExceptionDomain()
          Retrieves the exception domain of this ServiceException.
 BasicException getExceptionStack()
          Return a StackedException, this exception object's cause.
 int getLineNr()
          Deprecated. use @{link ServiceException#getStackedException()} followed by
 String getMessage()
          Returns the detail message string of this RuntimeServiceException.
 String getMethodName()
          Deprecated. use @{link ServiceException#getStackedException()} followed by
 BasicException.Parameter[] getParameters()
          Deprecated. use @{link ServiceException#getStackedException()} followed by
 BasicException getStackedException()
          Deprecated. use getExceptionStack()
 BasicException getStackedException(int index)
          Deprecated. use @{link ServiceException#getStackedException()} followed by
 Date getTimestamp()
          Deprecated. use @{link ServiceException#getStackedException()} followed by
 Throwable initCause(Throwable cause)
          Initializes the cause of this throwable to the specified value.
 ServiceException log()
          Log the exception.
 void printStackTrace(PrintStream s)
           
 void printStackTrace(PrintWriter s)
           
 String stackToString()
          Deprecated. use @{link ServiceException#toString()}.
static ServiceException toServiceException(Exception exception)
          Deprecated. use new ServiceException(Exception)
 String toString()
          A String consisting of the class of this exception, the exception domain, the exception code, the exception description and the exception stack.
 String toString(String format)
          Returns a string representation for the exception's top level object using formatting information.
 
Methods inherited from class java.lang.Throwable
fillInStackTrace, getLocalizedMessage, getStackTrace, printStackTrace, setStackTrace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ServiceException

public ServiceException(BasicException exception)
Constructor

Parameters:
exception - the Exception to be wrapped

ServiceException

public ServiceException(Exception exception)
Constructor

Parameters:
exception - the Exception to be wrapped

ServiceException

public ServiceException(Exception cause,
                        String exceptionDomain,
                        int exceptionCode,
                        BasicException.Parameter[] parameters,
                        String description)
Creates a new ServiceException.

Parameters:
cause - The exception cause.
exceptionDomain - The exception domain or null for the default exception domain containing negative exception codes only.
exceptionCode - The exception code. Negative codes are shared by all exception domains, while positive ones are (non-default) exception domain specific.
parameters - The exception specific parameters.
description - A readable description usually not including the parameters.

ServiceException

public ServiceException(String exceptionDomain,
                        int exceptionCode,
                        BasicException.Parameter[] parameters,
                        String description)
Creates a new ServiceException.

Parameters:
exceptionDomain - The exception domain or null for the default exception domain containing negative exception codes only.
exceptionCode - The exception code. Negative codes are shared by all exception domains, while positive ones are (non-default) exception domain specific.
parameters - The exception specific parameters.
message - A readable description not including the parameters.
Method Detail

log

public ServiceException log()
Log the exception.

Returns:
the ServiceException

appendCause

public ServiceException appendCause(Throwable cause)

getStackedException

public final BasicException getStackedException()
Deprecated. use getExceptionStack()

Returns:
the BasicException wrapped by this object.

getExceptionStack

public BasicException getExceptionStack()
Return a StackedException, this exception object's cause.

Specified by:
getExceptionStack in interface BasicException.Wrapper
Returns:
the BasicException wrapped by this object.

getExceptionDomain

public String getExceptionDomain()
Retrieves the exception domain of this ServiceException.

Specified by:
getExceptionDomain in interface BasicException.Wrapper
Returns:
the exception domain

getExceptionCode

public int getExceptionCode()
Retrieves the exception code of this ServiceException.

Specified by:
getExceptionCode in interface BasicException.Wrapper
Returns:
the exception code

getCause

public BasicException getCause(String exceptionDomain)
Returns the cause belonging to a specific exception domain.

Specified by:
getCause in interface BasicException.Wrapper
Parameters:
exceptionDomain - the desired exception domain, or null to retrieve the initial cause.
Returns:
Either the cause belonging to a specific exception domain or the initial cause if exceptionDomain is null.

getMessage

public String getMessage()
Returns the detail message string of this RuntimeServiceException.

Specified by:
getMessage in interface BasicException.Wrapper
Overrides:
getMessage in class Throwable
Returns:
the detail message string of this Wrapper exception instance (which may be null).

toString

public String toString()
A String consisting of the class of this exception, the exception domain, the exception code, the exception description and the exception stack.

Overrides:
toString in class Throwable
Returns:
a multiline representation of this exception.

initCause

public Throwable initCause(Throwable cause)
Initializes the cause of this throwable to the specified value. (The cause is the throwable that caused this throwable to get thrown.)

Overrides:
initCause in class Throwable
Parameters:
cause - the cause (which is saved for later retrieval by the getCause() method). (A null value is permitted, and indicates that the cause is nonexistent or unknown.)
Returns:
a reference to this RuntimeServiceException instance.
Throws:
IllegalArgumentException - if cause is this throwable. (A throwable cannot be its own cause.)
IllegalStateException - if the cause is already set.

getCause

public Throwable getCause()
Returns the cause of an exception. The cause actually is the wrapped exception.

Overrides:
getCause in class Throwable
Returns:
Throwable The exception cause.

stackToString

public String stackToString()
Deprecated. use @{link ServiceException#toString()}.

Returns a formatted multiline String representation for the exception including all stacked exceptions. Includes all available exception information as timestamp, class, method, line, number, domain, error code, description, parameters and the stack trace for each exception.

Returns:
a String representation *

getStackedException

public BasicException getStackedException(int index)
Deprecated. use @{link ServiceException#getStackedException()} followed by


getClassName

public String getClassName()
Deprecated. use @{link ServiceException#getStackedException()} followed by

Retrieves the class for this ServiceExceptionDescriptor object.

Returns:
the class

getMethodName

public String getMethodName()
Deprecated. use @{link ServiceException#getStackedException()} followed by

Retrieves the method for this ServiceExceptionDescriptor object.

Returns:
the method

getLineNr

public int getLineNr()
Deprecated. use @{link ServiceException#getStackedException()} followed by

Retrieves the line number for this ServiceExceptionDescriptor object.

Returns:
the line nr

getDomain

public String getDomain()
Deprecated. use @{link ServiceException#getExceptionDomain()}.

Retrieves the domain for this ServiceException toplevel object.

Returns:
the domain value

getErrorCode

public int getErrorCode()
Deprecated. use @{link ServiceException#getStackedException()} followed by

Retrieves the error code for this ServiceException toplevel object.

Returns:
the error code

getTimestamp

public Date getTimestamp()
Deprecated. use @{link ServiceException#getStackedException()} followed by

Retrieves the timestamp for this ServiceException toplevel object.

Returns:
the timestamp

getParameters

public BasicException.Parameter[] getParameters()
Deprecated. use @{link ServiceException#getStackedException()} followed by

Retrieves the parameters for this ServiceException toplevel object.

Returns:
the parameters or an empty array if there are no parameters available

getDescription

public String getDescription()
Deprecated. use @{link ServiceException#getStackedException()} followed by

Retrieves the context for this ServiceException toplevel object.

Returns:
the description

toString

public String toString(String format)
Returns a string representation for the exception's top level object using formatting information. The string rendering may be parameterized by passing a format string containing text mixed with placeholders for the excpetions properties and the exception parameters. If the format string is null or empty the default string representation is returned. Any number of placeholders may be woven into format string. The placeholders are defined through "%{PLACEHOLDER}" elements. Example format strings: "Authorization denied for user=%{user} using role %{role}" "Error in %{EX_CLASS}.%{EX_METHOD} at line %{EX_LINE}" If a placeholder cannot be resolved it is replaced by "". {PLACEHOLDER} actually represents the unresolveable placeholder name.

Defined placeholders for exception properties: Any exception property name is a valid placeholder. Multivalue properties are rendered like arrays ("[value1,value2, ...]") Defined placeholders for exception parameters: EX_TIMESTAMP the exception's timestamp as "yyyy-MM-dd HH:mm:ss.SSS" EX_CLASS the exception's class name EX_METHOD the exception's method name EX_LINE the exception's line number EX_DOMAIN the exception's domain EX_ERRORCODE the exception's error code EX_DESCRIPTION the exception's description

Parameters:
format - a format string
Returns:
a string representation

printStackTrace

public void printStackTrace(PrintStream s)
Overrides:
printStackTrace in class Throwable

printStackTrace

public void printStackTrace(PrintWriter s)
Overrides:
printStackTrace in class Throwable

toServiceException

public static ServiceException toServiceException(Exception exception)
Deprecated. use new ServiceException(Exception)

Map a throwable to a ServiceException

Parameters:
throwable - a throwable to be mapped to a ServiceException
Returns:
the throwable itself in case of a ServiceException; a ServiceException wrapping the throwable otherwise


This software is published under the BSD license. Copyright © 2003-2007, OMEX AG, Switzerland, All rights reserved. Use is subject to license terms.