com.day.util.WrappedRuntimeException Maven / Gradle / Ivy
/**
* $Id: WrappedRuntimeException.java 12345 2004-08-22 04:56:09Z fielding $
*
* Copyright 1997-2004 Day Management AG
* Barfuesserplatz 6, 4001 Basel, Switzerland
* All Rights Reserved.
*
* This software is the confidential and proprietary information of
* Day Management AG, ("Confidential Information"). You shall not
* disclose such Confidential Information and shall use it only in
* accordance with the terms of the license agreement you entered into
* with Day.
*
*/
package com.day.util;
import java.io.PrintStream;
import java.io.PrintWriter;
/**
* An Exception that wraps another Throwable, and prints its wrapped exception's
* stack trace as well as its own when printStackTrace is called.
*
* @version $Revision: 1.10 $, $Date: 2004-08-22 06:56:09 +0200 (Sun, 22 Aug 2004) $
* @author benp
* @audience core
*/
public abstract class WrappedRuntimeException extends RuntimeException {
/** Root failure cause */
protected Throwable rootException;
/**
* Class constructor that creates a WrappedException
given
* a message describing the failure cause
* @param s description
*/
public WrappedRuntimeException(String s) {
super(s);
}
/**
* Class constructor that creates a WrappedException
given
* a message describing the failure cause and a root exception
* @param s description
* @param e root failure cause
*/
public WrappedRuntimeException(String s, Throwable e) {
super(s);
}
/**
* Class constructor that creates a WrappedException
given
* a root exception
* @param e root failure cause
*/
public WrappedRuntimeException(Exception e) {
this(null, e);
}
/**
* Returns the error message string of this exception.
* @return error message string of this exception.
*/
public String getMessage() {
String s = super.getMessage();
if (rootException == null) {
return s;
} else {
String s2 = rootException.getMessage();
return s == null ? s2 : s + ": " + s2;
}
}
/**
* Returns the root exception of this exception.
* @return the root exception of this exception
*/
public Throwable getRootException() {
return rootException;
}
/**
* Prints this WrappedException
and its backtrace to the
* standard error stream.
*/
public void printStackTrace() {
synchronized (System.err) {
super.printStackTrace();
if (rootException != null) {
rootException.printStackTrace();
}
}
}
/**
* Prints this WrappedException
and its backtrace to the
* specified print stream.
* @param s PrintStream
to use for output
*/
public void printStackTrace(PrintStream s) {
synchronized (s) {
super.printStackTrace(s);
if (rootException != null) {
rootException.printStackTrace(s);
}
}
}
/**
* Prints this WrappedException
and its backtrace to
* the specified print writer.
* @param s PrintWriter
to use for output
*/
public void printStackTrace(PrintWriter s) {
synchronized (s) {
super.printStackTrace(s);
if (rootException != null) {
rootException.printStackTrace(s);
}
}
}
}