2 * @(#)AFSException.java 2.0 01/04/16
4 * Copyright (c) 2001 International Business Machines Corp.
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
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.
24 package org.openafs.jafs;
26 import java.util.Locale;
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.
32 * @version 1.0, 04/16/2001
33 * @see java.lang.Exception
35 public class AFSException extends Exception
38 * The AFS specific error number (code).
39 * @see #getErrorCode()
44 * Constructs an <code>AFSException</code> with the specified detail
47 * @param reason the detail message.
49 public AFSException(String reason)
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.
58 * @param errno the AFS error number (error code).
60 public AFSException(int errno)
62 super(ErrorTable.getMessage( (errno == 0) ? ErrorTable.UNKNOWN : errno ));
63 this.errno = (errno == 0) ? ErrorTable.UNKNOWN : errno;
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.
74 * @param reason the detail message.
75 * @param errno the AFS error number (error code).
77 public AFSException(String reason, int errno)
82 /*-----------------------------------------------------------------------*/
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>.
88 * @return the AFS error code of this <code>AFSException</code>
90 * @see ErrorTable#getMessage(int)
92 public int getErrorCode()
96 /*-----------------------------------------------------------------------*/
98 * Returns the error message string of this exception.
100 * @return the error message string of this exception object.
102 * @see #getAFSMessage()
104 public String getMessage()
106 String msg = super.getMessage();
107 return (msg == null) ? ErrorTable.getMessage(errno) : msg;
109 /*-----------------------------------------------------------------------*/
111 * Returns the locale specific error message string of this exception.
113 * @return the error message string of this exception object.
114 * @param locale the locale for which this message will be displayed
116 * @see #getAFSMessage()
118 public String getMessage(Locale locale)
120 String msg = super.getMessage();
121 return (msg == null) ? ErrorTable.getMessage(errno, locale) : msg;
123 /*-----------------------------------------------------------------------*/
125 * Returns the AFS error message string defined by the <code>ErrorTable
126 * </code> class. The message will be formatted according to the default
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.
136 * @return the AFS error message string of this exception object.
138 * @see #getAFSMessage(Locale)
139 * @see AFSException#AFSException(String, int)
140 * @see ErrorTable#getMessage(int)
141 * @see java.lang.Exception#getMessage()
143 public String getAFSMessage()
145 return ErrorTable.getMessage(errno);
147 /*-----------------------------------------------------------------------*/
149 * Returns the AFS error message defined by the <code>ErrorTable</code>
150 * class. The message will be formatted according to the specified Locale.
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.
159 * @return the AFS error message string of this exception object.
160 * @param locale the locale for which this message will be displayed
162 * @see #getAFSMessage()
163 * @see AFSException#AFSException(String, int)
164 * @see ErrorTable#getMessage(int, Locale)
165 * @see java.lang.Exception#getMessage()
167 public String getAFSMessage(Locale locale)
169 return ErrorTable.getMessage(errno, locale);
171 /*-----------------------------------------------------------------------*/
173 * Returns a string representation of this AFS Exception.
175 * <P> The message will be formatted according to the specified Locale.
177 * @return the AFS error message string of this exception object.
179 * @see #getAFSMessage()
180 * @see ErrorTable#getMessage(int)
181 * @see java.lang.Exception#getMessage()
183 public String toString()
185 return "AFSException: Error Code: " + errno + "; Message: " +
188 /*-----------------------------------------------------------------------*/