2 ******************************************************************************
3 * Copyright (C) 1996-2005, International Business Machines Corporation and *
4 * others. All Rights Reserved. *
5 ******************************************************************************
7 ******************************************************************************
10 package com.ibm.icu4jni.common;
13 * Error exception class mapping ICU error codes of the enum UErrorCode
14 * @author syn wee quek
17 public final class ErrorCode extends Exception
20 // public methods --------------------------------------------------------
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.
29 public static final RuntimeException getException(int error)
31 if (error <= U_ZERO_ERROR && error >= U_ERROR_LIMIT) {
34 String errorname = ERROR_NAMES_[U_ILLEGAL_ARGUMENT_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);
45 return new RuntimeException(errorname);
49 // public static data member ---------------------------------------------
52 * Start of information results (semantically successful)
54 public static final int U_ERROR_INFO_START = -128;
56 * A resource bundle lookup returned a fallback result (not an error)
58 public static final int U_USING_FALLBACK_ERROR = -128;
60 * A resource bundle lookup returned a result from the root locale (not an
63 public static final int U_USING_DEFAULT_ERROR = -127;
65 * A SafeClone operation required allocating memory (informational
68 public static final int U_SAFECLONE_ALLOCATED_ERROR = -126;
70 * This must always be the last warning value to indicate the limit for
71 * UErrorCode warnings (last warning code +1)
73 public static final int U_ERROR_INFO_LIMIT = -125;
76 * No error, no warning
78 public static final int U_ZERO_ERROR = 0;
80 * Start of codes indicating failure
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;
87 * Indicates a bug in the library code
89 public static final int U_INTERNAL_PROGRAM_ERROR = 5;
90 public static final int U_MESSAGE_PARSE_ERROR = 6;
92 * Memory allocation error
94 public static final int U_MEMORY_ALLOCATION_ERROR = 7;
95 public static final int U_INDEX_OUTOFBOUNDS_ERROR = 8;
97 * Equivalent to Java ParseException
99 public static final int U_PARSE_ERROR = 9;
101 * In the Character conversion routines: Invalid character or sequence was
104 public static final int U_INVALID_CHAR_FOUND = 10;
106 * In the Character conversion routines: More bytes are required to complete
107 * the conversion successfully
109 public static final int U_TRUNCATED_CHAR_FOUND = 11;
111 * In codeset conversion: a sequence that does NOT belong in the codepage has
114 public static final int U_ILLEGAL_CHAR_FOUND = 12;
116 * Conversion table file found, but corrupted
118 public static final int U_INVALID_TABLE_FORMAT = 13;
120 * Conversion table file not found
122 public static final int U_INVALID_TABLE_FILE = 14;
124 * A result would not fit in the supplied buffer
126 public static final int U_BUFFER_OVERFLOW_ERROR = 15;
128 * Requested operation not supported in current context
130 public static final int U_UNSUPPORTED_ERROR = 16;
132 * an operation is requested over a resource that does not support it
134 public static final int U_RESOURCE_TYPE_MISMATCH = 17;
136 * ISO-2022 illlegal escape sequence
138 public static final int U_ILLEGAL_ESCAPE_SEQUENCE = 18;
140 * ISO-2022 unsupported escape sequence
142 public static final int U_UNSUPPORTED_ESCAPE_SEQUENCE = 19;
144 * No space available for in-buffer expansion for Arabic shaping
146 public static final int U_NO_SPACE_AVAILABLE = 20;
148 * This must always be the last value to indicate the limit for UErrorCode
149 * (last error code +1)
151 public static final int U_ERROR_LIMIT = 21;
155 public static boolean LIBRARY_LOADED = false;
157 // private data member ----------------------------------------------------
160 * Array of error code names corresponding to the errorcodes.
161 * ie ERROR_NAMES_[0] = name of U_ZERO_ERROR
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"
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
181 public static String getErrorName(int ec){
182 return ERROR_NAMES_[ec];
186 * Returns true if the input error code denotes success
187 * @param ec int value of the error code
191 public static boolean isSuccess(int ec){
192 return (ec<=U_ZERO_ERROR);
196 * Returns true if the input error code denotes failure
197 * @param ec int value of the error code
201 public static boolean isFailure(int ec){
202 return (ec>U_ZERO_ERROR);