views:

82

answers:

1

Dear colleagues, I need raise an exception from C++ code. Raised exception must contain text and code of error. So common form:

ThrowNew(jclass clazz, const char *msg)

is not applicable. That is why I want create my own instance of java class:

public class MyException extends Exception

that contains one more property for code. But JNI interface has only declaration for

Throw(jthrowable obj)

Is it correct to cast instance of MyException to jthrowable ?

+1  A: 

For the JVM jthrowable is an instance of java.lang.Throwable so if you instantiate the exception in your JNI code and cast it, it should work.

Daff
@Daff :) I have already tried, it is really works, but would it work on all platforms or using some new JDK?
Dewfy
I'm using it in Linux and Windows and didn't have a problem. Since it is part of the JVM (and Exceptions have always been a part of Java) you shouldn't expect any problems.
Daff