001/*
002 * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved.
003 * 
004 * This software is open source. 
005 * See the bottom of this file for the licence.
006 * 
007 * $Id: DocumentException.java,v 1.2 2001/06/09 13:29:38 jstrachan Exp $
008 */
009
010package org.dom4j;
011
012import java.io.PrintStream;
013import java.io.PrintWriter;
014
015/** <p><code>DocumentException</code> is a nested Exception which may be thrown
016  * during the processing of a DOM4J document.
017  *
018  * @author <a href="mailto:james.strachan@metastuff.com">James Strachan</a>
019  * @version $Revision: 1.2 $
020  */
021public class DocumentException extends Exception {
022
023    /** A wrapped <code>Throwable</code> */
024    private Throwable nestedException;
025    
026
027    public DocumentException() {
028        super("Error occurred in DOM4J application.");
029    }
030
031    public DocumentException(String message) {
032        super(message);
033    }
034    
035    public DocumentException(Throwable nestedException) {
036        super(nestedException.getMessage());    
037        this.nestedException = nestedException;
038    }    
039
040    public DocumentException(String message, Throwable nestedException) {
041        super(message);    
042        this.nestedException = nestedException;
043    }    
044
045    public Throwable getNestedException() {
046        return nestedException;
047    }
048    
049    public String getMessage() {
050        if (nestedException != null) {
051            return super.getMessage() + " Nested exception: " + nestedException.getMessage();
052        } else {
053            return super.getMessage();
054        }
055    }
056
057    public void printStackTrace() {
058        super.printStackTrace();
059        if (nestedException != null) {
060            System.err.print("Nested exception: ");
061            nestedException.printStackTrace();
062        }
063    }
064
065    public void printStackTrace(PrintStream out) {
066        super.printStackTrace(out);
067        if (nestedException != null) {
068            out.println("Nested exception: ");
069            nestedException.printStackTrace(out);
070        }
071    }
072
073    public void printStackTrace(PrintWriter writer) {
074        super.printStackTrace(writer);
075        if (nestedException != null) {
076            writer.println("Nested exception: ");
077            nestedException.printStackTrace(writer);
078        }
079    }
080}
081
082
083
084
085/*
086 * Redistribution and use of this software and associated documentation
087 * ("Software"), with or without modification, are permitted provided
088 * that the following conditions are met:
089 *
090 * 1. Redistributions of source code must retain copyright
091 *    statements and notices.  Redistributions must also contain a
092 *    copy of this document.
093 *
094 * 2. Redistributions in binary form must reproduce the
095 *    above copyright notice, this list of conditions and the
096 *    following disclaimer in the documentation and/or other
097 *    materials provided with the distribution.
098 *
099 * 3. The name "DOM4J" must not be used to endorse or promote
100 *    products derived from this Software without prior written
101 *    permission of MetaStuff, Ltd.  For written permission,
102 *    please contact dom4j-info@metastuff.com.
103 *
104 * 4. Products derived from this Software may not be called "DOM4J"
105 *    nor may "DOM4J" appear in their names without prior written
106 *    permission of MetaStuff, Ltd. DOM4J is a registered
107 *    trademark of MetaStuff, Ltd.
108 *
109 * 5. Due credit should be given to the DOM4J Project
110 *    (http://dom4j.org/).
111 *
112 * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS
113 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
114 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
115 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
116 * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
117 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
118 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
119 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
120 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
121 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
122 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
123 * OF THE POSSIBILITY OF SUCH DAMAGE.
124 *
125 * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved.
126 *
127 * $Id: DocumentException.java,v 1.2 2001/06/09 13:29:38 jstrachan Exp $
128 */