com.sonalb
Class EnhancedRuntimeException

java.lang.Object
  extended by java.lang.Throwable
      extended by java.lang.Exception
          extended by java.lang.RuntimeException
              extended by com.sonalb.EnhancedRuntimeException
All Implemented Interfaces:
IEnhancedException, java.io.Serializable

public class EnhancedRuntimeException
extends java.lang.RuntimeException
implements IEnhancedException

Convenience implementation of IEnhancedException interface, and subclass of RuntimeException.

Setter methods for the error code, causal Exception, class and method of origin, and data Object are provided. However, once these fields have been set, any subsequent calls to the respective setters throws an UnsupportedOperationException.

Author:
Sonal Bansal
See Also:
IEnhancedException, RuntimeException, Serialized Form

Constructor Summary
EnhancedRuntimeException()
          Constructs a "plain vanilla" EnhancedRuntimeException.
EnhancedRuntimeException(java.lang.Exception under)
          Constructs an EnhancedRuntimeException with the specified causal Exception.
EnhancedRuntimeException(java.lang.String s)
          Constructs an EnhancedRuntimeException with a short detail message.
EnhancedRuntimeException(java.lang.String s, java.lang.Exception under)
          Constructs an EnhancedRuntimeException with the specified detail message and causal Exception.
EnhancedRuntimeException(java.lang.String s, java.lang.Exception under, java.lang.String code, java.lang.Object o, java.lang.String method)
          Constructs an EnhancedRuntimeException with a detail message, causal Exception, error code, class and method of origin.
EnhancedRuntimeException(java.lang.String code, java.lang.Object o, java.lang.String method)
          Constructs an EnhancedRuntimeException with an error code and, class and method of origin.
EnhancedRuntimeException(java.lang.String s, java.lang.String code, java.lang.Object o, java.lang.String method)
          Constructs an EnhancedRuntimeException with a detail message, error code, class and method of origin.
 
Method Summary
 java.lang.Exception getCausalException()
          Returns the underlying Exception (if any) for this instance.
 java.lang.String getCode()
          Returns the application-specific error code associated with this instance.
 java.lang.Object getDataObject()
          Returns the data object (if any) set by the originator.
 java.lang.String getOriginClass()
          Returns the fully-qualified name of the class which constructed this instance.
 java.lang.String getOriginMethod()
          Returns the name of the method in which this instance was constructed.
 void removeDataObject()
          Removes the data object (if any) contained in this instance.
 void setCausalException(java.lang.Exception e)
          Sets the underlying (causal) Exception for this instance.
 void setCode(java.lang.String c)
          Sets the error-code which identifies the particular error condition that triggered this exception.
 void setDataObject(java.lang.Object o)
          Sets the data Object which will be passed up the call stack.
 void setOriginClass(java.lang.Object o)
          Sets the class of origin for this instance.
 void setOriginMethod(java.lang.String meth)
          Sets the method of origin for this instance.
 java.lang.String toString()
          Returns a short description of this instance.
 
Methods inherited from class java.lang.Throwable
fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EnhancedRuntimeException

public EnhancedRuntimeException()
Constructs a "plain vanilla" EnhancedRuntimeException.


EnhancedRuntimeException

public EnhancedRuntimeException(java.lang.String s)
Constructs an EnhancedRuntimeException with a short detail message.

Parameters:
s - the detail message.

EnhancedRuntimeException

public EnhancedRuntimeException(java.lang.Exception under)
Constructs an EnhancedRuntimeException with the specified causal Exception.

Parameters:
under - the causal Exception.
See Also:
Exception

EnhancedRuntimeException

public EnhancedRuntimeException(java.lang.String s,
                                java.lang.Exception under)
Constructs an EnhancedRuntimeException with the specified detail message and causal Exception.

Parameters:
under - the causal Exception.
s - the detail message.
See Also:
Exception

EnhancedRuntimeException

public EnhancedRuntimeException(java.lang.String s,
                                java.lang.Exception under,
                                java.lang.String code,
                                java.lang.Object o,
                                java.lang.String method)
Constructs an EnhancedRuntimeException with a detail message, causal Exception, error code, class and method of origin. For example,
...
throw new EnhancedRuntimeException("Failed to connect to server", excp, "SVR_0090", this, "connect");
...

Parameters:
under - the causal Exception.
s - the detail message.
code - the error-code.
o - the Object from which the class of origin is determined.
method - the method of origin.
See Also:
Exception

EnhancedRuntimeException

public EnhancedRuntimeException(java.lang.String code,
                                java.lang.Object o,
                                java.lang.String method)
Constructs an EnhancedRuntimeException with an error code and, class and method of origin. For example,
...
throw new EnhancedRuntimeException("SVR_0090", this, "connect");
...

Parameters:
code - the error-code.
o - the Object from which the class of origin is determined.
method - the method of origin.

EnhancedRuntimeException

public EnhancedRuntimeException(java.lang.String s,
                                java.lang.String code,
                                java.lang.Object o,
                                java.lang.String method)
Constructs an EnhancedRuntimeException with a detail message, error code, class and method of origin. For example,
...
throw new EnhancedRuntimeException("Failed to connect to server", "SVR_0090", this, "connect");
...

Parameters:
under - the causal Exception.
s - the detail message.
code - the error-code.
o - the Object from which the class of origin is determined.
method - the method of origin.
See Also:
Exception
Method Detail

getCausalException

public java.lang.Exception getCausalException()
Description copied from interface: IEnhancedException
Returns the underlying Exception (if any) for this instance.

Specified by:
getCausalException in interface IEnhancedException
Returns:
the underlying (causal) Exception ; null if there is none.

getOriginClass

public java.lang.String getOriginClass()
Description copied from interface: IEnhancedException
Returns the fully-qualified name of the class which constructed this instance.

Specified by:
getOriginClass in interface IEnhancedException
Returns:
the String representing the class of origin ; "UNKNOWN" if it was not set.

getOriginMethod

public java.lang.String getOriginMethod()
Description copied from interface: IEnhancedException
Returns the name of the method in which this instance was constructed.

Specified by:
getOriginMethod in interface IEnhancedException
Returns:
the String representing the method of origin ; "UNKNOWN" if it was not set.

getCode

public java.lang.String getCode()
Description copied from interface: IEnhancedException
Returns the application-specific error code associated with this instance.

Specified by:
getCode in interface IEnhancedException
Returns:
the String representing the error code ; "UNSPECIFIED" if it was not set.

setDataObject

public void setDataObject(java.lang.Object o)
                   throws java.lang.UnsupportedOperationException
Sets the data Object which will be passed up the call stack.

Parameters:
o - the data Object.
Throws:
java.lang.UnsupportedOperationException - Thrown if the data Object has already been set.

getDataObject

public java.lang.Object getDataObject()
Description copied from interface: IEnhancedException
Returns the data object (if any) set by the originator.

Specified by:
getDataObject in interface IEnhancedException
Returns:
the Object ; null if there is none.

removeDataObject

public void removeDataObject()
Description copied from interface: IEnhancedException
Removes the data object (if any) contained in this instance.

Specified by:
removeDataObject in interface IEnhancedException

setCode

public void setCode(java.lang.String c)
             throws java.lang.UnsupportedOperationException
Sets the error-code which identifies the particular error condition that triggered this exception.

Parameters:
c - the error code.
Throws:
java.lang.UnsupportedOperationException - Thrown if the error code has already been set.

setOriginClass

public void setOriginClass(java.lang.Object o)
                    throws java.lang.UnsupportedOperationException
Sets the class of origin for this instance. The class of origin is taken as the value returned by o.getClass().getName(). However, if the parameter is itself an instance of Class, then the class of origin is taken as o.getName().

Parameters:
o - the Object representing the class of origin.
Throws:
java.lang.UnsupportedOperationException - Thrown if the class of origin has already been set.
See Also:
Class

setOriginMethod

public void setOriginMethod(java.lang.String meth)
                     throws java.lang.UnsupportedOperationException
Sets the method of origin for this instance.

Parameters:
meth - the String representing the method of origin.
Throws:
java.lang.UnsupportedOperationException - Thrown if the method of origin has already been set.

setCausalException

public void setCausalException(java.lang.Exception e)
                        throws java.lang.UnsupportedOperationException
Sets the underlying (causal) Exception for this instance.

Parameters:
e - the Exception representing the causal Exception.
Throws:
java.lang.UnsupportedOperationException - Thrown if the causal Exception has already been set.

toString

public java.lang.String toString()
Returns a short description of this instance. If this instance does not contain the error code or the origin info, the returned String is same as would be returned by RuntimeException.toString(). Otherwise, the returned String is formed by concatenating the following :-

Overrides:
toString in class java.lang.Throwable
Returns:
the String representation of this EnhancedRuntimeException.
See Also:
Throwable.toString()