Home | History | Annotate | Download | only in native
      1 /*
      2  * Copyright (C) 2010 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #include "JniException.h"
     18 #include "JNIHelp.h"
     19 
     20 bool maybeThrowIcuException(JNIEnv* env, UErrorCode error) {
     21     if (U_SUCCESS(error)) {
     22         return false;
     23     }
     24     const char* message = u_errorName(error);
     25     switch (error) {
     26     case U_ILLEGAL_ARGUMENT_ERROR:
     27         return jniThrowException(env, "java/lang/IllegalArgumentException", message);
     28     case U_INDEX_OUTOFBOUNDS_ERROR:
     29     case U_BUFFER_OVERFLOW_ERROR:
     30         return jniThrowException(env, "java/lang/ArrayIndexOutOfBoundsException", message);
     31     case U_UNSUPPORTED_ERROR:
     32         return jniThrowException(env, "java/lang/UnsupportedOperationException", message);
     33     default:
     34         return jniThrowRuntimeException(env, message);
     35     }
     36 }
     37 
     38 void jniThrowExceptionWithErrno(JNIEnv* env, const char* exceptionClassName, int error) {
     39     char buf[BUFSIZ];
     40     jniThrowException(env, exceptionClassName, jniStrError(error, buf, sizeof(buf)));
     41 }
     42 
     43 void jniThrowOutOfMemoryError(JNIEnv* env, const char* message) {
     44     jniThrowException(env, "java/lang/OutOfMemoryError", message);
     45 }
     46 
     47 void jniThrowSocketException(JNIEnv* env, int error) {
     48     jniThrowExceptionWithErrno(env, "java/net/SocketException", error);
     49 }
     50