Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / JAVA / classes / org / openafs / jafs / AFSException.java
1 /*
2 * @(#)AFSException.java 2.0 01/04/16
3 *
4 * Copyright (c) 2001 International Business Machines Corp.
5 * All rights reserved.
6 *
7 * This software has been released under the terms of the IBM Public
8 * License. For details, see the LICENSE file in the top-level source
9 * directory or online at http://www.openafs.org/dl/license10.html
10 *
11 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
12 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
13 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
14 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
15 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
16 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
17 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
18 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
19 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
20 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22 */
23
24 package org.openafs.jafs;
25
26 import java.util.Locale;
27
28 /**
29 * An exception indicating that an error has occurred in the Java AFS
30 * API, in the Java AFS JNI, or in the AFS file system.
31 *
32 * @version 1.0, 04/16/2001
33 * @see java.lang.Exception
34 */
35 public class AFSException extends Exception
36 {
37 /**
38 * The AFS specific error number (code).
39 * @see #getErrorCode()
40 */
41 protected int errno;
42
43 /**
44 * Constructs an <code>AFSException</code> with the specified detail
45 * message.
46 *
47 * @param reason the detail message.
48 */
49 public AFSException(String reason)
50 {
51 super(reason);
52 }
53 /**
54 * Constructs an <code>AFSException</code> with the specified error code.
55 * This constructor will also generate the appropriate error message
56 * respective to the specified error code.
57 *
58 * @param errno the AFS error number (error code).
59 */
60 public AFSException(int errno)
61 {
62 super(ErrorTable.getMessage( (errno == 0) ? ErrorTable.UNKNOWN : errno ));
63 this.errno = (errno == 0) ? ErrorTable.UNKNOWN : errno;
64 }
65 /**
66 * Constructs an <code>AFSException</code> with the specified detail message
67 * and specified error code. In this constructor the specified detail message
68 * overrides the default AFS error message defined by the
69 * <code>ErrorTable</code> class. Therefore, to retrieve the AFS specific
70 * error message, you must use the <code>{@link #getAFSMessage}</code> method.
71 * The <code>{@link #getMessage}</code> method will return the message specified
72 * in this constructor.
73 *
74 * @param reason the detail message.
75 * @param errno the AFS error number (error code).
76 */
77 public AFSException(String reason, int errno)
78 {
79 super(reason);
80 this.errno = errno;
81 }
82 /*-----------------------------------------------------------------------*/
83 /**
84 * Returns the AFS specific error number (code). This code can be interpreted
85 * by use of the <code>{@link ErrorTable}</code> class method
86 * <code>{@link ErrorTable#getMessage(int)}</code>.
87 *
88 * @return the AFS error code of this <code>AFSException</code>
89 * object.
90 * @see ErrorTable#getMessage(int)
91 */
92 public int getErrorCode()
93 {
94 return errno;
95 }
96 /*-----------------------------------------------------------------------*/
97 /**
98 * Returns the error message string of this exception.
99 *
100 * @return the error message string of this exception object.
101 *
102 * @see #getAFSMessage()
103 */
104 public String getMessage()
105 {
106 String msg = super.getMessage();
107 return (msg == null) ? ErrorTable.getMessage(errno) : msg;
108 }
109 /*-----------------------------------------------------------------------*/
110 /**
111 * Returns the locale specific error message string of this exception.
112 *
113 * @return the error message string of this exception object.
114 * @param locale the locale for which this message will be displayed
115 *
116 * @see #getAFSMessage()
117 */
118 public String getMessage(Locale locale)
119 {
120 String msg = super.getMessage();
121 return (msg == null) ? ErrorTable.getMessage(errno, locale) : msg;
122 }
123 /*-----------------------------------------------------------------------*/
124 /**
125 * Returns the AFS error message string defined by the <code>ErrorTable
126 * </code> class. The message will be formatted according to the default
127 * Locale.
128 *
129 * <P> This message is also available from this object's super class
130 * method <code>getMessage</code>. However, this method will always return
131 * the string message associated with the actual AFS error code/number
132 * specified, whereas the {@link #getMessage()} method will return the
133 * string message intended for this Exception object, which may be
134 * an overridden message defined in the constructor of this Exception.
135 *
136 * @return the AFS error message string of this exception object.
137 *
138 * @see #getAFSMessage(Locale)
139 * @see AFSException#AFSException(String, int)
140 * @see ErrorTable#getMessage(int)
141 * @see java.lang.Exception#getMessage()
142 */
143 public String getAFSMessage()
144 {
145 return ErrorTable.getMessage(errno);
146 }
147 /*-----------------------------------------------------------------------*/
148 /**
149 * Returns the AFS error message defined by the <code>ErrorTable</code>
150 * class. The message will be formatted according to the specified Locale.
151 *
152 * <P> This message is also available from this object's super class
153 * method <code>getMessage</code>. However, this method will always return
154 * the string message associated with the actual AFS error code/number
155 * specified, whereas the {@link #getMessage()} method will return the
156 * string message intended for this Exception object, which may be
157 * an overridden message defined in the constructor of this Exception.
158 *
159 * @return the AFS error message string of this exception object.
160 * @param locale the locale for which this message will be displayed
161 *
162 * @see #getAFSMessage()
163 * @see AFSException#AFSException(String, int)
164 * @see ErrorTable#getMessage(int, Locale)
165 * @see java.lang.Exception#getMessage()
166 */
167 public String getAFSMessage(Locale locale)
168 {
169 return ErrorTable.getMessage(errno, locale);
170 }
171 /*-----------------------------------------------------------------------*/
172 /**
173 * Returns a string representation of this AFS Exception.
174 *
175 * <P> The message will be formatted according to the specified Locale.
176 *
177 * @return the AFS error message string of this exception object.
178 *
179 * @see #getAFSMessage()
180 * @see ErrorTable#getMessage(int)
181 * @see java.lang.Exception#getMessage()
182 */
183 public String toString()
184 {
185 return "AFSException: Error Code: " + errno + "; Message: " +
186 getMessage();
187 }
188 /*-----------------------------------------------------------------------*/
189 }
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204