KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javassist > CannotCompileException


1 /*
2  * Javassist, a Java-bytecode translator toolkit.
3  * Copyright (C) 1999-2005 Shigeru Chiba. All Rights Reserved.
4  *
5  * The contents of this file are subject to the Mozilla Public License Version
6  * 1.1 (the "License"); you may not use this file except in compliance with
7  * the License. Alternatively, the contents of this file may be used under
8  * the terms of the GNU Lesser General Public License Version 2.1 or later.
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  */

15
16 package javassist;
17
18 import javassist.compiler.CompileError;
19
20 /**
21  * Thrown when bytecode transformation has failed.
22  */

23 public class CannotCompileException extends Exception JavaDoc {
24     private String JavaDoc message;
25     private Throwable JavaDoc cause;
26
27     public String JavaDoc getReason() {
28         if (message != null)
29             return message;
30         else
31             return this.toString();
32     }
33
34     /**
35      * Constructs a CannotCompileException with a message.
36      *
37      * @param msg the message.
38      */

39     public CannotCompileException(String JavaDoc msg) {
40         super(msg);
41         message = msg;
42         cause = null;
43     }
44
45     /**
46      * Constructs a CannotCompileException with an <code>Exception</code>
47      * representing the cause.
48      *
49      * @param e the cause.
50      */

51     public CannotCompileException(Throwable JavaDoc e) {
52         super("by " + e.toString());
53         message = null;
54         cause = e;
55     }
56
57     /**
58      * Constructs a CannotCompileException with a detailed message
59      * and an <code>Exception</code> representing the cause.
60      *
61      * @param msg the message.
62      * @param e the cause.
63      */

64     public CannotCompileException(String JavaDoc msg, Throwable JavaDoc e) {
65         this(msg);
66         cause = e;
67     }
68
69     /**
70      * Constructs a CannotCompileException with a
71      * <code>NotFoundException</code>.
72      */

73     public CannotCompileException(NotFoundException e) {
74         this("cannot find " + e.getMessage(), e);
75     }
76
77     /**
78      * Constructs a CannotCompileException with an <code>CompileError</code>.
79      */

80     public CannotCompileException(CompileError e) {
81         this("[source error] " + e.getMessage(), e);
82     }
83
84     /**
85      * Constructs a CannotCompileException
86      * with a <code>ClassNotFoundException</code>.
87      */

88     public CannotCompileException(ClassNotFoundException JavaDoc e, String JavaDoc name) {
89         this("cannot find " + name, e);
90     }
91
92     /**
93      * Constructs a CannotCompileException with a ClassFormatError.
94      */

95     public CannotCompileException(ClassFormatError JavaDoc e, String JavaDoc name) {
96         this("invalid class format: " + name, e);
97     }
98
99     /**
100      * Prints this exception and its backtrace.
101      */

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