Name: rlT66838 Date: 07/25/97 1. Build test.class and native.dll using the files below. 2. run "java test". You will see that that the native method returned even though there should still be a thrown exception. The problem is caused by the fact the exceptionDescribe in exceptions.c uses execute_java_dynamic_method to call printStackTrace. execute_java_dynamic_method clears any thrown exceptions right before it calls the java method. /* begin test.java */ class TestExcept2 extends Exception { } class test { public static void main( String[] args ) { test t = new test(); t.useJNI(); System.out.println("useJNI returned"); } public void throwExcept2() throws TestExcept2 { throw new TestExcept2(); } public native void useJNI(); static { System.loadLibrary("native"); } } /* end test.java */ /* begin native.cpp */ #include <jni.h> #include "test.h" #include <stdio.h> extern "C" { JNIEXPORT void JNICALL Java_test_useJNI (JNIEnv * env, jobject o) { jclass jc1, jc2; jobject jo1; int i; jmethodID id; printf("ExceptionOccurred\n=============================================\n"); jc1 = env->GetObjectClass( o ); id = ( jmethodID ) env->GetMethodID( jc1, "throwExcept2", "()V"); env->CallVoidMethod( o, id ); jo1 = env->ExceptionOccurred(); printf("ExceptionDescribe\n=============================================\n"); env->ExceptionDescribe(); } } /* end native.cpp */ company - Symantec Corp. , email - ###@###.### ======================================================================
|