All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.day.util.WrappedException Maven / Gradle / Ivy

/**
 * $Id: WrappedException.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.11 $, $Date: 2004-08-22 06:56:09 +0200 (Sun, 22 Aug 2004) $
 * @author benp
 * @audience core
 */
public abstract class WrappedException extends Exception {

    /** Root failure cause */
    protected Throwable rootException;

    /**
     * Class constructor that creates a WrappedException given
     * a message describing the failure cause
     * @param s description
     */
    public WrappedException(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 WrappedException(String s, Throwable e) {
        super(s);
	rootException = e;
    }

    /**
     * Class constructor that creates a WrappedException given
     * a root exception
     * @param t root failure cause
     */
    public WrappedException(Throwable t) {
        this(null, t);
    }

    /**
     * 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
     * @since JDK1.1
     */
    public void printStackTrace(PrintWriter s) {
	synchronized (s) {
	    super.printStackTrace(s);
            if (rootException != null) {
                rootException.printStackTrace(s);
            }
	}
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy