com.mcdermottroe.exemplar
Class Exception

java.lang.Object
  extended by java.lang.Throwable
      extended by java.lang.Exception
          extended by com.mcdermottroe.exemplar.Exception
All Implemented Interfaces:
Copyable<Exception>, Serializable, Comparable<Exception>
Direct Known Subclasses:
CopyException, InputException, LexerException, MessageException, OutputException, ParameterEntityException, ParserException, XMLDocumentTypeException, XMLParserGeneratorException

public abstract class Exception
extends Exception
implements Comparable<Exception>, Copyable<Exception>

A base class for all of the exceptions in the program. This is intended to provide nice chained exception backtraces for all derived exceptions.

Since:
0.1
See Also:
Serialized Form

Constructor Summary
protected Exception()
          Exception without a description.
protected Exception(String message)
          Exception with a description.
protected Exception(String message, Throwable cause)
          Exception with a description and a reference to an exception which caused it.
protected Exception(Throwable cause)
          Exception with a reference to the exception that caused it.
 
Method Summary
 int compareTo(Exception other)
          Implement Comparable.compareTo(Object).
protected static StackTraceElement[] copyStackTrace(StackTraceElement[] t)
          A helper method for the implementations of Copyable.getCopy() in child classes of this class to deep-copy a stack trace.
 boolean equals(Object o)
          Implement Object.equals(Object) in a way which will be consistent with hashCode().
private static String exceptionStackTrace(Throwable t)
          Get the stack trace from the point at which the given exception was thrown.
 List<String> getBackTrace()
          Get the backtrace as a List of Strings.
 int hashCode()
          Implement Object.hashCode() in a way which will be consistent with equals(Object).
private static boolean throwablesEqual(Throwable a, Throwable b)
          Recursively test that two Throwables are equal.
 String toString()
          Provide a full backtrace of all the exceptions which caused this exception to be thrown, (with a stacktrace for each exception if debugging is turned on).
 
Methods inherited from class java.lang.Throwable
fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.mcdermottroe.exemplar.Copyable
getCopy
 

Constructor Detail

Exception

protected Exception()
Exception without a description.


Exception

protected Exception(String message)
Exception with a description.

Parameters:
message - The description of the exception.

Exception

protected Exception(String message,
                    Throwable cause)
Exception with a description and a reference to an exception which caused it.

Parameters:
message - The description of the exception.
cause - The cause of the exception.

Exception

protected Exception(Throwable cause)
Exception with a reference to the exception that caused it.

Parameters:
cause - The cause of the exception.
Method Detail

getBackTrace

public List<String> getBackTrace()
Get the backtrace as a List of Strings.

Returns:
A List where each element is a step in the backtrace.

copyStackTrace

protected static StackTraceElement[] copyStackTrace(StackTraceElement[] t)
A helper method for the implementations of Copyable.getCopy() in child classes of this class to deep-copy a stack trace.

Parameters:
t - The stack trace to copy.
Returns:
A deep-copy of the stack trace.

equals

public boolean equals(Object o)
Implement Object.equals(Object) in a way which will be consistent with hashCode().

Overrides:
equals in class Object
Parameters:
o - The other Object to compare with.
Returns:
True if this is equal to o, false otherwise.

throwablesEqual

private static boolean throwablesEqual(Throwable a,
                                       Throwable b)
Recursively test that two Throwables are equal. This is necessary because Throwable uses the default Object.equals(Object) which only compares referential equality.

Parameters:
a - The first of the two Throwables.
b - The second of the two Throwables.
Returns:
True if the two Throwables are equal.

hashCode

public int hashCode()
Implement Object.hashCode() in a way which will be consistent with equals(Object).

Overrides:
hashCode in class Object
Returns:
A hash code for this object.

toString

public String toString()
Provide a full backtrace of all the exceptions which caused this exception to be thrown, (with a stacktrace for each exception if debugging is turned on).

Overrides:
toString in class Throwable
Returns:
A descriptive debugging String for this Exception.

exceptionStackTrace

private static String exceptionStackTrace(Throwable t)
Get the stack trace from the point at which the given exception was thrown.

Parameters:
t - The Throwable to get the stack trace from.
Returns:
A String representation of the stack trace in the format of one frame per line. All lines are indented by Strings.indent(String).

compareTo

public int compareTo(Exception other)
Implement Comparable.compareTo(Object).

Specified by:
compareTo in interface Comparable<Exception>
Parameters:
other - The Exception to compare against.
Returns:
A result as defined by Comparable.compareTo(Object).