test 123
[mir.git] / source / mir / misc / ConfigException.java
1 /*
2  * Copyright (C) 2001, 2002 The Mir-coders group
3  *
4  * This file is part of Mir.
5  *
6  * Mir is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * Mir is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Mir; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  * In addition, as a special exception, The Mir-coders gives permission to link
21  * the code of this program with  any library licensed under the Apache Software License, 
22  * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library 
23  * (or with modified versions of the above that use the same license as the above), 
24  * and distribute linked combinations including the two.  You must obey the 
25  * GNU General Public License in all respects for all of the code used other than 
26  * the above mentioned libraries.  If you modify this file, you may extend this 
27  * exception to your version of the file, but you are not obligated to do so.  
28  * If you do not wish to do so, delete this exception statement from your version.
29  */
30
31 package mir.misc;
32
33
34
35 /**
36  * Reports the location of the error in the File.
37  * Based and inspired by a source from the Ant distribution
38  * (Copyright (c) 1999-2001 The Apache Software Foundation.)
39  *
40  * @version $Id: ConfigException.java,v 1.4 2003/04/21 12:42:52 idfx Exp $
41  *
42  * @author The Mir-coders group
43  */
44
45 public class ConfigException extends RuntimeException {
46
47     /** Exception that might have caused this one. */
48     private Throwable cause;
49
50     /** Location in the build file where the exception occured */
51     private Location location = Location.UNKNOWN_LOCATION;
52
53     /**
54      * Constructs a build exception with no descriptive information.
55      */
56     public ConfigException() {
57         super();
58     }
59
60     /**
61      * Constructs an exception with the given descriptive message.
62      * @param msg Description of or information about the exception.
63      */
64     public ConfigException(String msg) {
65         super(msg);
66     }
67
68     /**
69      * Constructs an exception with the given message and exception as
70      * a root cause.
71      * @param msg Description of or information about the exception.
72      * @param cause Throwable that might have cause this one.
73      */
74     public ConfigException(String msg, Throwable cause) {
75         super(msg);
76         this.cause = cause;
77     }
78
79     /**
80      * Constructs an exception with the given message and exception as
81      * a root cause and a location in a file.
82      * @param msg Description of or information about the exception.
83      * @param cause Exception that might have cause this one.
84      * @param location Location in the project file where the error occured.
85      */
86     public ConfigException(String msg, Throwable cause, Location location) {
87         this(msg, cause);
88         this.location = location;
89     }
90
91     /**
92      * Constructs an exception with the given exception as a root cause.
93      * @param cause Exception that might have caused this one.
94      */
95     public ConfigException(Throwable cause) {
96         super(cause.toString());
97         this.cause = cause;
98     }
99
100     /**
101      * Constructs an exception with the given descriptive message and a location
102      * in a file.
103      * @param msg Description of or information about the exception.
104      * @param location Location in the project file where the error occured.
105      */
106     public ConfigException(String msg, Location location) {
107         super(msg);
108         this.location = location;
109     }
110
111     /**
112      * Constructs an exception with the given exception as
113      * a root cause and a location in a file.
114      * @param cause Exception that might have cause this one.
115      * @param location Location in the project file where the error occured.
116      */
117     public ConfigException(Throwable cause, Location location) {
118         this(cause);
119         this.location = location;
120     }
121
122     /**
123      * Returns the nested exception.
124      */
125     public Throwable getException() {
126         return cause;
127     }
128
129     /**
130      * Returns the location of the error and the error message.
131      */
132     public String toString() {
133         return location.toString() + getMessage();
134     }
135
136     /**
137      * Sets the file location where the error occured.
138      */
139     public void setLocation(Location location) {
140         this.location = location;
141     }
142
143     /**
144      * Returns the file location where the error occured.
145      */
146     public Location getLocation() {
147         return location;
148     }
149
150     // Override stack trace methods to show original cause:
151     public void printStackTrace() {
152         printStackTrace(System.err);
153     }
154     
155 }