OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / libcore / luni / src / main / java / com / ibm / icu4jni / common / ErrorCode.java
1 /**
2 ******************************************************************************
3 * Copyright (C) 1996-2005, International Business Machines Corporation and   *
4 * others. All Rights Reserved.                                               *
5 ******************************************************************************
6 *
7 ******************************************************************************
8 */
9
10 package com.ibm.icu4jni.common;
11
12 /**
13 * Error exception class mapping ICU error codes of the enum UErrorCode
14 * @author syn wee quek
15 * @internal
16 */
17 public final class ErrorCode extends Exception
18 {
19
20   // public methods --------------------------------------------------------
21
22   /**
23   * Generic mapping from the error codes to java default exceptions.
24   * @param error error code
25   * @return java default exception that maps to the argument error code,
26   *         otherwise if error is not a valid error code, null is returned.
27   * @stable ICU 2.4
28   */
29   public static final RuntimeException getException(int error)
30   {
31     if (error <= U_ZERO_ERROR && error >= U_ERROR_LIMIT) {
32       return null;
33     }
34     String errorname = ERROR_NAMES_[U_ILLEGAL_ARGUMENT_ERROR];
35     switch (error) {
36       case U_ILLEGAL_ARGUMENT_ERROR :
37         return new IllegalArgumentException(errorname);
38       case U_INDEX_OUTOFBOUNDS_ERROR :
39         return new ArrayIndexOutOfBoundsException(errorname);
40       case U_BUFFER_OVERFLOW_ERROR :
41         return new ArrayIndexOutOfBoundsException(errorname);
42       case U_UNSUPPORTED_ERROR :
43         return new UnsupportedOperationException(errorname);
44       default :
45         return new RuntimeException(errorname);
46     }
47   }
48
49   // public static data member ---------------------------------------------
50
51   /**
52   * Start of information results (semantically successful)
53   */
54   public static final int U_ERROR_INFO_START = -128;
55   /**
56   * A resource bundle lookup returned a fallback result (not an error)
57   */
58   public static final int U_USING_FALLBACK_ERROR = -128;
59   /**
60   * A resource bundle lookup returned a result from the root locale (not an
61   * error)
62   */
63   public static final int U_USING_DEFAULT_ERROR = -127;
64   /**
65   * A SafeClone operation required allocating memory (informational
66   * only
67   */
68   public static final int U_SAFECLONE_ALLOCATED_ERROR = -126;
69   /**
70   * This must always be the last warning value to indicate the limit for
71   * UErrorCode warnings (last warning code +1)
72   */
73   public static final int U_ERROR_INFO_LIMIT = -125;
74
75   /**
76   * No error, no warning
77   */
78   public static final int U_ZERO_ERROR = 0;
79   /**
80   * Start of codes indicating failure
81   */
82   public static final int U_ILLEGAL_ARGUMENT_ERROR = 1;
83   public static final int U_MISSING_RESOURCE_ERROR = 2;
84   public static final int U_INVALID_FORMAT_ERROR = 3;
85   public static final int U_FILE_ACCESS_ERROR = 4;
86   /**
87   * Indicates a bug in the library code
88   */
89   public static final int U_INTERNAL_PROGRAM_ERROR = 5;
90   public static final int U_MESSAGE_PARSE_ERROR = 6;
91   /**
92   * Memory allocation error
93   */
94   public static final int U_MEMORY_ALLOCATION_ERROR = 7;
95   public static final int U_INDEX_OUTOFBOUNDS_ERROR = 8;
96   /**
97   * Equivalent to Java ParseException
98   */
99   public static final int U_PARSE_ERROR = 9;
100   /**
101   * In the Character conversion routines: Invalid character or sequence was
102   * encountered
103   */
104   public static final int U_INVALID_CHAR_FOUND = 10;
105   /**
106   * In the Character conversion routines: More bytes are required to complete
107   * the conversion successfully
108   */
109   public static final int U_TRUNCATED_CHAR_FOUND = 11;
110   /**
111   * In codeset conversion: a sequence that does NOT belong in the codepage has
112   * been encountered
113   */
114   public static final int U_ILLEGAL_CHAR_FOUND = 12;
115   /**
116   * Conversion table file found, but corrupted
117   */
118   public static final int U_INVALID_TABLE_FORMAT = 13;
119   /**
120   * Conversion table file not found
121   */
122   public static final int U_INVALID_TABLE_FILE = 14;
123   /**
124   * A result would not fit in the supplied buffer
125   */
126   public static final int U_BUFFER_OVERFLOW_ERROR = 15;
127   /**
128   * Requested operation not supported in current context
129   */
130   public static final int U_UNSUPPORTED_ERROR = 16;
131   /**
132   * an operation is requested over a resource that does not support it
133   */
134   public static final int U_RESOURCE_TYPE_MISMATCH = 17;
135   /**
136   * ISO-2022 illlegal escape sequence
137   */
138   public static final int U_ILLEGAL_ESCAPE_SEQUENCE = 18;
139   /**
140   * ISO-2022 unsupported escape sequence
141   */
142   public static final int U_UNSUPPORTED_ESCAPE_SEQUENCE = 19;
143   /**
144   * No space available for in-buffer expansion for Arabic shaping
145   */
146   public static final int U_NO_SPACE_AVAILABLE = 20;
147   /**
148   * This must always be the last value to indicate the limit for UErrorCode
149   * (last error code +1)
150   */
151   public static final int U_ERROR_LIMIT = 21;
152   /**
153   * Load library flag
154   */
155   public static boolean LIBRARY_LOADED = false;
156
157   // private data member ----------------------------------------------------
158
159   /**
160   * Array of error code names corresponding to the errorcodes.
161   * ie ERROR_NAMES_[0] = name of U_ZERO_ERROR
162   */
163   private static final String ERROR_NAMES_[] = {
164     "U_ZERO_ERROR",               "U_ILLEGAL_ARGUMENT_ERROR",
165     "U_MISSING_RESOURCE_ERROR",   "U_INVALID_FORMAT_ERROR",
166     "U_FILE_ACCESS_ERROR",        "U_INTERNAL_PROGRAM_ERROR",
167     "U_MESSAGE_PARSE_ERROR",      "U_MEMORY_ALLOCATION_ERROR",
168     "U_INDEX_OUTOFBOUNDS_ERROR",  "U_PARSE_ERROR",
169     "U_INVALID_CHAR_FOUND",       "U_TRUNCATED_CHAR_FOUND",
170     "U_ILLEGAL_CHAR_FOUND",       "U_INVALID_TABLE_FORMAT",
171     "U_INVALID_TABLE_FILE",       "U_BUFFER_OVERFLOW_ERROR",
172     "U_UNSUPPORTED_ERROR",        "U_RESOURCE_TYPE_MISMATCH",
173     "U_ILLEGAL_ESCAPE_SEQUENCE",  "U_UNSUPPORTED_ESCAPE_SEQUENCE"
174   };
175   /**
176    * Returns the error name of the input error code
177    * @param ec int value of the error code
178    * @return String name of the error code
179    * @stable ICU 2.4
180    */
181   public static String getErrorName(int ec){
182     return ERROR_NAMES_[ec];
183   }
184
185   /**
186    * Returns true if the input error code denotes success
187    * @param ec int value of the error code
188    * @return boolean
189    * @stable ICU 2.4
190    */
191   public static boolean isSuccess(int ec){
192     return (ec<=U_ZERO_ERROR);
193   }
194
195   /**
196    * Returns true if the input error code denotes failure
197    * @param ec int value of the error code
198    * @return boolean
199    * @stable ICU 2.4
200    */
201   public static boolean isFailure(int ec){
202     return (ec>U_ZERO_ERROR);
203   }
204 }
205