Friday 15 May 2015

Native Methods and Exceptions in Java

 Native methods can throw exceptions just like a regular Java method. As with any other method that throws an exception, the native method in the Java class must declare the exceptions that it can throw. This looks exactly like the throwsclause for any other method.
Your native code throws the actual exception using the SignalErrorfunction:
void SignalError(ExecEnv *ee, char *Exception, char *SourceHint);
The first argument is the exception environment to use for the exception. Generally, you will pass a NULLhere to indicate the current environment.
The second argument is the fully specified exception name. This name includes the package in which the exception is defined. It should also be specified as a path, replacing the usual period separators with forward slashes (that is, UNIX-style path separators).
The third argument is a source code hint. You can pass a string that describes the error or provides some useful details. This string will appear on the walkback if the exception is not handled. It is safe to pass a NULLhere. 

No comments:

Post a Comment