KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > picocontainer > PicoException


1 /*****************************************************************************
2  * Copyright (C) PicoContainer Organization. All rights reserved. *
3  * ------------------------------------------------------------------------- *
4  * The software in this package is published under the terms of the BSD *
5  * style license a copy of which has been included with this distribution in *
6  * the LICENSE.txt file. *
7  * *
8  * Original code by *
9  *****************************************************************************/

10 package org.picocontainer;
11
12 import java.io.PrintStream JavaDoc;
13 import java.io.PrintWriter JavaDoc;
14
15 /**
16  * Superclass for all Exceptions in PicoContainer. You can use this if you want to catch all exceptions thrown by
17  * PicoContainer. Be aware that some parts of the PicoContainer API will also throw {@link NullPointerException} when
18  * <code>null</code> values are provided for method arguments, and this is not allowed.
19  *
20  * @author Paul Hammant
21  * @author Aslak Helles&oslash;y
22  * @version $Revision: 1812 $
23  * @since 1.0
24  */

25 public abstract class PicoException extends RuntimeException JavaDoc {
26     /**
27      * The exception that caused this one.
28      */

29     private Throwable JavaDoc cause;
30
31     /**
32      * Construct a new exception with no cause and no detail message. Note modern JVMs may still track the exception
33      * that caused this one.
34      */

35     protected PicoException() {
36     }
37
38     /**
39      * Construct a new exception with no cause and the specified detail message. Note modern JVMs may still track the
40      * exception that caused this one.
41      *
42      * @param message the message detailing the exception.
43      */

44     protected PicoException(final String JavaDoc message) {
45         super(message);
46     }
47
48     /**
49      * Construct a new exception with the specified cause and no detail message.
50      *
51      * @param cause the exception that caused this one.
52      */

53     protected PicoException(final Throwable JavaDoc cause) {
54         this.cause = cause;
55     }
56
57     /**
58      * Construct a new exception with the specified cause and the specified detail message.
59      *
60      * @param message the message detailing the exception.
61      * @param cause the exception that caused this one.
62      */

63     protected PicoException(final String JavaDoc message, final Throwable JavaDoc cause) {
64         super(message);
65         this.cause = cause;
66     }
67
68     /**
69      * Retrieve the exception that caused this one.
70      *
71      * @return the exception that caused this one, or null if it was not set.
72      * @see Throwable#getCause() the method available since JDK 1.4 that is overridden by this method.
73      */

74     public Throwable JavaDoc getCause() {
75         return cause;
76     }
77
78     /**
79      * Overridden to provide 1.4 style stack traces on pre-1.4.
80      *
81      * @param s the {@link PrintStream} used to print the stack trace
82      */

83     public void printStackTrace() {
84         printStackTrace(System.err);
85     }
86
87     /**
88      * Overridden to provide 1.4 style stack traces on pre-1.4.
89      */

90     public void printStackTrace(PrintStream JavaDoc s) {
91         super.printStackTrace(s);
92         if(cause!=null) {
93             s.println("Caused by:\n");
94             cause.printStackTrace(s);
95         }
96     }
97
98     /**
99      * Overridden to provide 1.4 style stack traces on pre-1.4.
100      *
101      * @param s the {@link PrintWriter} used to print the stack trace
102      */

103     public void printStackTrace(PrintWriter JavaDoc s) {
104         super.printStackTrace(s);
105         if(cause!=null) {
106             s.println("Caused by:\n");
107             cause.printStackTrace(s);
108         }
109     }
110 }
111
Popular Tags