The Java interface / Advanced programming |
In order to catch Java™ exceptions within programs, use a TRY/CATCH block.
When a Java exception occurs, the runtime system sets the STATUS variable to the error code -8306.
To easily identify the type of the Java exceptions in your code, consider writing a library function based on ERR_GET(), that recognizes most common Java exceptions, and converts them to integer codes:
IMPORT JAVA java.lang.StringBuffer MAIN DEFINE sb java.lang.StringBuffer LET sb = StringBuffer.create("abcdef") TRY CALL sb.deleteCharAt(50) -- out of bounds! CATCH DISPLAY err_get(STATUS) EXIT PROGRAM 1 END TRY END MAIN