Rational Developer for System z
COBOL for Windows, Version 7.5, Programming Guide


Example: handling Java exceptions

The following example shows the use of JNI services for catching an exception from Java and the use of the PrintStackTrace method of java.lang.Throwable for error analysis.

Repository.
    Class JavaException is “java.lang.Exception”.
. . .
Local-storage section.
01 ex usage object reference JavaException.
Linkage section.
COPY “JNI.cpy”.
. . .
Procedure division.
    Set address of JNIEnv to JNIEnvPtr
    Set address of JNINativeInterface to JNIEnv
    . . .
    Invoke anObj “someMethod”
    Perform ErrorCheck
. . .
ErrorCheck.
    Call ExceptionOccurred
        using by value JNIEnvPtr
        returning ex
    If ex not = null then
        Call ExceptionClear using by value JNIEnvPtr
        Display “Caught an unexpected exception”
        Invoke ex “printStackTrace”
        Stop run
    End-if

Terms of use | Feedback

Copyright IBM Corporation 1996, 2008.
This information center is powered by Eclipse technology. (http://www.eclipse.org)