异常处理:如何在Java中捕获C ++异常

时间:2016-06-26 03:17:10

标签: java c++ exception exception-handling java-native-interface

EDITED: 我使用 SWIG在Java中实现了一些C ++代码。 C ++函数抛出了一个我无法用Java捕获的异常。每当达到异常时, JVM崩溃

爪哇:

try 
{
    myNativeClass = new myNativeClass();        
} 
catch (Throwable t) 
{
    System.out.println("There was an error in intializing myNativeClass");
}   

JNI调用的格式为:public final static native long new_myNativeClass();

C:

class myNativeClass 
{
    public:

    myNativeClass()
    {
        doSomthing();
    };
}
void myNativeClass::doSomthing()
{
  /*
    something nasty occurred here
  */ 
   throw -1;
}

0 个答案:

没有答案