OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / libcore / luni / src / main / native / ErrorCode.cpp
1 /**
2 *******************************************************************************
3 * Copyright (C) 1996-2005, International Business Machines Corporation and    *
4 * others. All Rights Reserved.                                                *
5 *******************************************************************************
6 *
7 *******************************************************************************
8 */
9
10 #include "ErrorCode.h"
11 #include "JNIHelp.h"
12
13 /**
14 * Checks if an error has occurred, throwing a suitable exception if so.
15 * @param env JNI environment
16 * @param errorCode code to determine if it is an error
17 * @return 0 if errorCode is not an error, 1 if errorCode is an error, but the
18 *         creation of the exception to be thrown fails
19  * @exception thrown if errorCode represents an error
20 */
21 UBool icu4jni_error(JNIEnv* env, UErrorCode errorCode)
22 {
23     const char* message = u_errorName(errorCode);
24     if (errorCode <= U_ZERO_ERROR || errorCode >= U_ERROR_LIMIT) {
25         return 0;
26     }
27
28     switch (errorCode) {
29     case U_ILLEGAL_ARGUMENT_ERROR:
30         return jniThrowException(env, "java/lang/IllegalArgumentException", message);
31     case U_INDEX_OUTOFBOUNDS_ERROR:
32     case U_BUFFER_OVERFLOW_ERROR:
33         return jniThrowException(env, "java/lang/ArrayIndexOutOfBoundsException", message);
34     case U_UNSUPPORTED_ERROR:
35         return jniThrowException(env, "java/lang/UnsupportedOperationException", message);
36     default:
37         return jniThrowRuntimeException(env, message);
38     }
39 }