/Users/lyon/j4p/src/javassist/CannotCompileException.java

1    /* 
2     * Javassist, a Java-bytecode translator toolkit. 
3     * Copyright (C) 1999-2003 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 { 
24       private String message; 
25    
26       public String getReason() { 
27           if (message != null) 
28               return message; 
29           else 
30               return this.toString(); 
31       } 
32    
33       /** 
34        * Constructs a CannotCompileException with a message. 
35        */ 
36       public CannotCompileException(String msg) { 
37           super(msg); 
38           message = msg; 
39       } 
40    
41       /** 
42        * Constructs a CannotCompileException with an <code>Exception</code>. 
43        */ 
44       public CannotCompileException(Exception e) { 
45           super("by " + e.toString()); 
46           message = null; 
47       } 
48    
49       /** 
50        * Constructs a CannotCompileException with a 
51        * <code>NotFoundException</code>. 
52        */ 
53       public CannotCompileException(NotFoundException e) { 
54           this("cannot find " + e.getMessage()); 
55       } 
56    
57       /** 
58        * Constructs a CannotCompileException with an <code>CompileError</code>. 
59        */ 
60       public CannotCompileException(CompileError e) { 
61           super("[source error] " + e.getMessage()); 
62           message = null; 
63       } 
64    
65       /** 
66        * Constructs a CannotCompileException 
67        * with a <code>ClassNotFoundException</code>. 
68        */ 
69       public CannotCompileException(ClassNotFoundException e, String name) { 
70           this("cannot find " + name); 
71       } 
72    
73       /** 
74        * Constructs a CannotCompileException with a ClassFormatError. 
75        */ 
76       public CannotCompileException(ClassFormatError e, String name) { 
77           this("invalid class format: " + name); 
78       } 
79   } 
80