KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > util > WrappedThrowableException


1 /*
2   Copyright (C) 2001 Renaud Pawlak <renaud@aopsys.com>
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful, but
10   WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public
15   License along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17   USA */

18
19 package org.objectweb.jac.util;
20
21 import java.lang.reflect.InvocationTargetException JavaDoc;
22
23
24
25 /**
26  * This runtime exeption wraps a regular exception so that JAC objects
27  * can also send non-runtime exceptions.
28  *
29  * @author <a HREF="mailto:pawlak@cnam.fr">Renaud Pawlak</a>
30  */

31
32 public class WrappedThrowableException extends RuntimeException JavaDoc {
33    
34     /** Strores the throwable object that is wrapped by this runtime
35         exception. */

36     private Throwable JavaDoc wrappedThrowable;
37    
38     /**
39      * Creates the wrapping exception.<p>
40      *
41      * @param wrappedThrowable the throwable that is wrapped by this
42      * exception
43      */

44     public WrappedThrowableException(Throwable JavaDoc wrappedThrowable) {
45         if (wrappedThrowable instanceof InvocationTargetException JavaDoc) {
46             this.wrappedThrowable =
47                 ((InvocationTargetException JavaDoc)wrappedThrowable).getTargetException();
48         } else {
49             this.wrappedThrowable = wrappedThrowable;
50         }
51     }
52
53     /**
54      * Gets the wrapped throwable.
55      *
56      * @return the wrapped throwable
57      */

58     public Throwable JavaDoc getWrappedThrowable() {
59         return wrappedThrowable;
60     }
61    
62     /**
63      * Returns the string depicting the exception. It is the message of
64      * the wrapped throwable.<p>
65      *
66      * @return the printable representation of the wrapped exception
67      */

68     public String JavaDoc toString() {
69         return "WrappedThrowableException("+wrappedThrowable.toString()+")";
70     }
71
72     /**
73      * Prints the stack trace that has been filled when the exception
74      * was created.<p>
75      *
76      * This method delegates to the wrapped throwable.<p>
77      */

78     public void printStackTrace() {
79         wrappedThrowable.printStackTrace();
80     }
81    
82     /**
83      * Prints the wrapped throwable and its backtrace to the
84      * specified print stream.
85      *
86      * @param s the stream
87      */

88     public void printStackTrace(java.io.PrintStream JavaDoc s) {
89         wrappedThrowable.printStackTrace(s);
90     }
91
92     /**
93      * Prints the wrapped throwable and its backtrace to the
94      * specified print writer.
95      *
96      * @param s the writer
97      */

98     public void printStackTrace(java.io.PrintWriter JavaDoc s) {
99         wrappedThrowable.printStackTrace(s);
100     }
101
102     /**
103      * Returns the error message string of the wrapped throwable
104      * object.<p>
105      *
106      * @return the error message string
107      */

108     public String JavaDoc getMessage() {
109         return wrappedThrowable.getMessage();
110     }
111
112     public String JavaDoc getLocalizedMessage() {
113         return wrappedThrowable.getLocalizedMessage();
114     }
115     
116     public Throwable JavaDoc getCause() {
117         return wrappedThrowable;
118     }
119 }
120
Popular Tags