KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > izforge > izpack > compiler > CompilerException


1 /*
2  * IzPack - Copyright 2001-2007 Julien Ponge, All Rights Reserved.
3  *
4  * http://www.izforge.com/izpack/
5  * http://developer.berlios.de/projects/izpack/
6  *
7  * Copyright 2001,2002 Marcus Stursberg
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */

21
22 package com.izforge.izpack.compiler;
23
24 /**
25  * Indicates a Failure to compile.
26  *
27  * @author Marcus Stursberg
28  */

29 public class CompilerException extends java.io.IOException JavaDoc
30 {
31
32     static final long serialVersionUID = 6247426753392546734L;
33
34     /**
35      * The throwable that caused this throwable to get thrown, or null if this throwable was not
36      * caused by another throwable, or if the causative throwable is unknown. If this field is equal
37      * to this throwable itself, it indicates that the cause of this throwable has not yet been
38      * initialized.
39      */

40     private Throwable JavaDoc _cause = this;
41
42     /**
43      * Construct a new exception with the specified message.
44      *
45      * @param message Description of the error
46      */

47     public CompilerException(String JavaDoc message)
48     {
49         super(message);
50     }
51
52     /**
53      * Construct a new exception with the specified message and wraps another cause.
54      *
55      * @param message Description of the error
56      * @param cause Throwable
57      */

58     public CompilerException(String JavaDoc message, Throwable JavaDoc cause)
59     {
60         super(message);
61         this._cause = cause;
62     }
63
64     /**
65      * Initializes the <i>cause</i> of this throwable to the specified value. (The cause is the
66      * throwable that caused this throwable to get thrown.)
67      *
68      * <p>
69      * This method can be called at most once. It is generally called from within the constructor,
70      * or immediately after creating the throwable. If this throwable was created with {@link
71      * #CompilerException(String,Throwable)}, this method cannot be called even once.
72      *
73      * @param cause the cause (which is saved for later retrieval by the {@link #getCause()}
74      * method). (A <code>null</code> value is permitted, and indicates that the cause is
75      * nonexistent or unknown.)
76      * @return a reference to this <code>Throwable</code> instance.
77      * @throws IllegalArgumentException if <code>cause</code> is this throwable. (A throwable
78      * cannot be its own cause.)
79      * @throws IllegalStateException if this throwable was created with {@link
80      * #CompilerException(String,Throwable)}, or this method has already been called on this
81      * throwable.
82      */

83     public synchronized Throwable JavaDoc initCause(Throwable JavaDoc cause)
84     {
85         if (this._cause != this) throw new IllegalStateException JavaDoc("Can't overwrite cause");
86         if (cause == this) throw new IllegalArgumentException JavaDoc("Self-causation not permitted");
87         this._cause = cause;
88         return this;
89     }
90
91     /**
92      * Returns the cause of this throwable or <code>null</code> if the cause is nonexistent or
93      * unknown. (The cause is the throwable that caused this throwable to get thrown.)
94      *
95      * <p>
96      * This implementation returns the cause that was supplied via one of the constructors requiring
97      * a <code>Throwable</code>, or that was set after creation with the
98      * {@link #initCause(Throwable)} method. While it is typically unnecessary to override this
99      * method, a subclass can override it to return a cause set by some other means. This is
100      * appropriate for a "legacy chained throwable" that predates the addition of chained exceptions
101      * to <code>Throwable</code>. Note that it is <i>not</i> necessary to override any of the
102      * <code>PrintStackTrace</code> methods, all of which invoke the <code>getCause</code>
103      * method to determine the cause of a throwable.
104      *
105      * @return the cause of this throwable or <code>null</code> if the cause is nonexistent or
106      * unknown.
107      */

108     public Throwable JavaDoc getCause()
109     {
110         return (_cause == this ? null : _cause);
111     }
112 }
113
Popular Tags