Best way to throw exceptions in JNI code?

前端 未结 4 1560
终归单人心
终归单人心 2020-12-02 10:09

I\'d like a consistent and simple way to throw exceptions in JNI code; something that handles chained exceptions (implicitly from the env->ExceptionOccurred method, or expli

4条回答
  •  独厮守ぢ
    2020-12-02 10:32

    I simply use 2 lines:

     sprintf(exBuffer, "NE%4.4X: Caller can %s %s print", marker, "log", "or");
     (*env)->ThrowNew(env, (*env)->FindClass(env, "java/lang/Exception"), exBuffer);
    

    Produces:

     Exception in thread "main" java.lang.Exception: NE0042: Caller can log or print.
    

提交回复
热议问题