KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > render > afp > exceptions > NestedRuntimeException


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 /* $Id: NestedRuntimeException.java 426576 2006-07-28 15:44:37Z jeremias $ */
19
20 package org.apache.fop.render.afp.exceptions;
21
22 import java.io.PrintStream JavaDoc;
23 import java.io.PrintWriter JavaDoc;
24
25 /**
26  * Handy class for wrapping runtime Exceptions with a root cause.
27  * This technique is no longer necessary in Java 1.4, which provides
28  * built-in support for exception nesting. Thus exceptions in applications
29  * written to use Java 1.4 need not extend this class.
30  *
31  */

32 public abstract class NestedRuntimeException extends RuntimeException JavaDoc {
33     
34     /** Root cause of this nested exception */
35     private Throwable JavaDoc _underlyingException;
36     
37     /**
38      * Construct a <code>NestedRuntimeException</code> with the specified detail message.
39      * @param msg The detail message.
40      */

41     public NestedRuntimeException(String JavaDoc msg) {
42         super(msg);
43     }
44     
45     /**
46      * Construct a <code>NestedRuntimeException</code> with the specified
47      * detail message and nested exception.
48      * @param msg The detail message.
49      * @param t The nested exception.
50      */

51     public NestedRuntimeException(String JavaDoc msg, Throwable JavaDoc t) {
52         super(msg);
53         _underlyingException = t;
54         
55     }
56     
57     /**
58      * Gets the original triggering exception
59      * @return The original exception as a throwable.
60      */

61     public Throwable JavaDoc getUnderlyingException() {
62         
63         return _underlyingException;
64         
65     }
66     
67     /**
68      * Return the detail message, including the message from the nested
69      * exception if there is one.
70      * @return The detail message.
71      */

72     public String JavaDoc getMessage() {
73         
74         if (_underlyingException == null) {
75             return super.getMessage();
76         } else {
77             return super.getMessage()
78             + "; nested exception is "
79                 + _underlyingException.getClass().getName();
80         }
81         
82     }
83     
84     /**
85      * Print the composite message and the embedded stack trace to the specified stream.
86      * @param ps the print stream
87      */

88     public void printStackTrace(PrintStream JavaDoc ps) {
89         if (_underlyingException == null) {
90             super.printStackTrace(ps);
91         } else {
92             ps.println(this);
93             _underlyingException.printStackTrace(ps);
94         }
95     }
96     
97     /**
98      * Print the composite message and the embedded stack trace to the specified writer.
99      * @param pw the print writer
100      */

101     public void printStackTrace(PrintWriter JavaDoc pw) {
102         if (_underlyingException == null) {
103             super.printStackTrace(pw);
104         } else {
105             pw.println(this);
106             _underlyingException.printStackTrace(pw);
107         }
108     }
109     
110 }
111
Popular Tags