When using a JNI function whose return value cannot flag that an error has occurred, native code must rely on the raised exception to do error checks. The JNI function that performs checks for a pending exception in the current thread is ExceptionOccurred. (ExceptionCheck was also added in Java 2 SDK release 1.2.) For example, the JNI function CallIntMethod cannot encode an error condition in the return value. Typical choices of error condition return values, such as NULL and -1, do not work because they could be legal values returned by the method that was called. Consider a Fraction class whose floor method returns the integral part of the value of the fraction, and some native code that calls this method. 
 public class Fraction {
     // details such as constructors omitted
     int over, under;
     public int floor() {
         return Math.floor((double)over/under);
     }
 }
 /* Native code that calls Fraction.floor. Assume method ID
    MID_Fraction_floor has been initialized elsewhere. */
 void f(JNIEnv *env, jobject fraction)
 {
     jint floor = (*env)->CallIntMethod(env, fraction,
                                        MID_Fraction_floor);
     /* important: check if an exception was raised */
     if ((*env)->ExceptionCheck(env)) {         return;
     }
     ... /* use floor */
 }
http://java.sun.com/docs/books/jni/html/exceptions.html
楼主参考文档里的用法试试

解决方案 »

  1.   

    问题已解决,供参考! TSETJOBJECT(pJNIEnv, m_jobjFileOutputStream, (jobject)pJNIEnv->NewObject(m_jclsFileOutputStream, m_jmidFileOutputStream, path));
    第一点问题,此处调用宏,宏中再调用宏,会导致二次异常,因为需考虑转换为局部变量;
           // 向Java端抛出异常
            jclass jclsExcp=pJNIEnv->FindClass("java/io/FileNotFoundException");
            pJNIEnv->ThrowNew(jclsExcp, "Exception From JNI!");
            pJNIEnv->ExceptionClear();
            TSETJOBJECT(pJNIEnv, jclsExcp, NULL);第二点问题,涉及到异常处理的原理问题,在异常处理块中不能再抛出异常,否则会导致程序崩溃.