Handling Java exceptions
Use JNI services to throw and catch Java™ exceptions.
Throwing an exception: Use one of the following services to throw a Java exception from a COBOL method:
You must make the thrown object an instance of a subclass of java.lang.Throwable.
The Java virtual machine (JVM) does not recognize and process the thrown exception until the method that contains the call has completed and returned to the JVM.
Catching an exception: After you invoke a method that might have thrown a Java exception, you can do these steps:
- Test whether an exception occurred.
- If an exception occurred, process the exception.
- Clear the exception, if clearing is appropriate.
Use the following JNI services:
To do error analysis, use the methods supported by the exception object that is returned. This object is an instance of the java.lang.Throwable class.