What happens when I throw a C++ exception from a native Java method?

前端 未结 5 1669
时光取名叫无心
时光取名叫无心 2020-12-08 07:22

Suppose I\'m embedding Sun\'s JVM in a C++ application. Through JNI I call a Java method (my own), which in turns calls a native method I implemented in a shared library.

5条回答
  •  时光说笑
    2020-12-08 08:24

    JNI uses c functions to interface with native code. C cannot handle exceptions correctly since it is not aware of their existence. So you have to catch the exceptions in your Native code and convert them to java exceptions or your jvm will crash. (This works since the java exception is only thrown once the native code returns to java)

提交回复
热议问题