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