summaryrefslogtreecommitdiffstats
path: root/icu/src/main/native
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2009-10-01 11:20:29 -0700
committerElliott Hughes <enh@google.com>2009-10-01 11:20:29 -0700
commit738f95037e3e00ec5ccb8686f7c4c5c2cc16e06a (patch)
treea803f5fda92fe4a84c6f00d76db4f8e20e4a61ae /icu/src/main/native
parent109fc1115e7afd2907544b805eaa2cc8a0e2635f (diff)
downloadlibcore-738f95037e3e00ec5ccb8686f7c4c5c2cc16e06a.zip
libcore-738f95037e3e00ec5ccb8686f7c4c5c2cc16e06a.tar.gz
libcore-738f95037e3e00ec5ccb8686f7c4c5c2cc16e06a.tar.bz2
Use jniThrowException instead of FindClass/ThrowNew.
Always use our best-of-breed code for throwing exceptions. The remaining callers of Throw have good reason, and the only caller of ThrowNew is now JNIHelp.c (jniThrowException) itself.
Diffstat (limited to 'icu/src/main/native')
-rw-r--r--icu/src/main/native/ErrorCode.c62
1 files changed, 22 insertions, 40 deletions
diff --git a/icu/src/main/native/ErrorCode.c b/icu/src/main/native/ErrorCode.c
index b3e43cd..94c4239 100644
--- a/icu/src/main/native/ErrorCode.c
+++ b/icu/src/main/native/ErrorCode.c
@@ -8,50 +8,32 @@
*/
#include "ErrorCode.h"
-
-/* private data members ----------------------------------------------------*/
-
-/**
-* Name of the java runtime exception classes
-*/
-#define ILLEGALARGUMENTEXCEPTION_ "java/lang/IllegalArgumentException"
-#define ARRAYINDEXOUTOFBOUNDSEXCEPTION_ "java/lang/ArrayIndexOutOfBoundsException"
-#define UNSUPPORTEDOPERATIONEXCEPTION_ "java/lang/UnsupportedOperationException"
-#define RUNTIMEEXCEPTION_ "java/lang/RuntimeException"
-
-/* public methods ---------------------------------------------------------*/
+#include "JNIHelp.h"
/**
-* Checks if an error has occured.
-* Throws a generic Java RuntimeException if an error has occured.
-* @param env JNI environment variable
-* @param errorcode code to determine if it is an erro
-* @return 0 if errorcode is not an error, 1 if errorcode is an error, but the
+* Checks if an error has occurred, throwing a suitable exception if so.
+* @param env JNI environment
+* @param errorCode code to determine if it is an error
+* @return 0 if errorCode is not an error, 1 if errorCode is an error, but the
* creation of the exception to be thrown fails
-* @exception thrown if errorcode represents an error
+ * @exception thrown if errorCode represents an error
*/
-UBool icu4jni_error(JNIEnv *env, UErrorCode errorcode)
+UBool icu4jni_error(JNIEnv *env, UErrorCode errorCode)
{
- const char *emsg = u_errorName(errorcode);
- jclass exception;
-
- if (errorcode > U_ZERO_ERROR && errorcode < U_ERROR_LIMIT) {
- switch (errorcode) {
- case U_ILLEGAL_ARGUMENT_ERROR :
- exception = (*env)->FindClass(env, ILLEGALARGUMENTEXCEPTION_);
- break;
- case U_INDEX_OUTOFBOUNDS_ERROR :
- case U_BUFFER_OVERFLOW_ERROR :
- exception = (*env)->FindClass(env, ARRAYINDEXOUTOFBOUNDSEXCEPTION_);
- break;
- case U_UNSUPPORTED_ERROR :
- exception = (*env)->FindClass(env, UNSUPPORTEDOPERATIONEXCEPTION_);
- break;
- default :
- exception = (*env)->FindClass(env, RUNTIMEEXCEPTION_);
+ const char* message = u_errorName(errorCode);
+ if (errorCode <= U_ZERO_ERROR || errorCode >= U_ERROR_LIMIT) {
+ return 0;
+ }
+
+ switch (errorCode) {
+ case U_ILLEGAL_ARGUMENT_ERROR:
+ return jniThrowException(env, "java/lang/IllegalArgumentException", message);
+ case U_INDEX_OUTOFBOUNDS_ERROR:
+ case U_BUFFER_OVERFLOW_ERROR:
+ return jniThrowException(env, "java/lang/ArrayIndexOutOfBoundsException", message);
+ case U_UNSUPPORTED_ERROR:
+ return jniThrowException(env, "java/lang/UnsupportedOperationException", message);
+ default:
+ return jniThrowException(env, "java/lang/RuntimeException", message);
}
-
- return ((*env)->ThrowNew(env, exception, emsg) != 0);
- }
- return 0;
}