View Javadoc
1   /*
2    * Copyright 2005 Werner Guttmann
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5    * in compliance with the License. You may obtain a copy of the License at
6    *
7    * http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software distributed under the License
10   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11   * or implied. See the License for the specific language governing permissions and limitations under
12   * the License.
13   */
14  package org.castor.xmlctf.compiler;
15  
16  import java.io.PrintStream;
17  import java.io.PrintWriter;
18  
19  /**
20   * Exception that signals a compilation error.
21   */
22  public class CompilationException extends RuntimeException {
23    /** SerialVersionUID. */
24    private static final long serialVersionUID = -1459631801932567828L;
25  
26    /** The cause for this exception. */
27    private Throwable _cause;
28  
29    /**
30     * Creates an instance of this exception type.
31     */
32    public CompilationException() {
33      super();
34    }
35  
36    /**
37     * Creates an instance of this exception type.
38     * 
39     * @param message The error message
40     * @param cause The root cause
41     */
42    public CompilationException(final String message, final Throwable cause) {
43      super(message);
44      _cause = cause;
45    }
46  
47    /**
48     * Creates an instance of this exception type.
49     * 
50     * @param message The error message
51     */
52    public CompilationException(final String message) {
53      super(message);
54    }
55  
56    /**
57     * Creates an instance of this exception type.
58     * 
59     * @param cause The root cause
60     */
61    public CompilationException(final Throwable cause) {
62      super();
63      _cause = cause;
64    }
65  
66    /**
67     * Match the JDK 1.4 Throwable version of getCause() on JDK<1.4 systems.
68     *
69     * @return The throwable cause of this exception.
70     */
71    public final Throwable getCause() {
72      return _cause;
73    }
74  
75    /**
76     * Print a stack trace to stderr.
77     */
78    public final void printStackTrace() {
79      // Print the stack trace for this exception.
80      super.printStackTrace();
81  
82      if (_cause != null) {
83        System.err.print("Caused by: ");
84        _cause.printStackTrace();
85      }
86    }
87  
88    /**
89     * Print a stack trace to the specified PrintStream.
90     *
91     * @param s The PrintStream to print a stack trace to.
92     */
93    public final void printStackTrace(final PrintStream s) {
94      // Print the stack trace for this exception.
95      super.printStackTrace(s);
96  
97      if (_cause != null) {
98        s.print("Caused by: ");
99        _cause.printStackTrace(s);
100     }
101   }
102 
103   /**
104    * Print a stack trace to the specified PrintWriter.
105    *
106    * @param w The PrintWriter to print a stack trace to.
107    */
108   public final void printStackTrace(final PrintWriter w) {
109     // Print the stack trace for this exception.
110     super.printStackTrace(w);
111 
112     if (_cause != null) {
113       w.print("Caused by: ");
114       _cause.printStackTrace(w);
115     }
116   }
117 
118 }