Problem:
entry "Jexception" using lnkException.
invoke lnkException "display"
How does one modify this example so that the text can be accessed in a move statement to a COBOL pic x field?
Resolution:
$set ooctrl ( p-f)
program-id. ExceptionCatcher.
class-control.
SimpleClass is class "$JAVA$SimpleClass"
EntryCallback is class "entrycll"
JavaExceptionManager is class "javaexpt"
ExceptionManager is class "exptnmgr"
javasup is class "javasup"
.
working-storage section.
01 theInstance object reference.
01 wsCallback object reference.
01 theJavaException object reference.
01 errorMessage pic x(255).
local-storage section.
01 filler pic x. *> dummy storage to allow the local entry
*> point to be used for the callback
linkage section.
01 lnkException object reference.
procedure division.
*>---Set up Exception handler
invoke EntryCallback "new" using z"JException"
returning wsCallback
invoke ExceptionManager "register"
using javaexceptionmanager
wsCallback
*>---Instantiate the class
invoke SimpleClass "new" returning theInstance
display "instantiated"
invoke theInstance "TestException"
display "excepted"
stop run.
entry "Jexception" using lnkException.
display "Jexception: Exception occurred"
invoke javasup "exceptionOccurred"
returning theJavaException
end-invoke
if theJavaException not = null
display "Jexception: retrieve exception's content"
invoke theJavaException "printStackTrace"
invoke theJavaException "toString"
returning errorMessage
end-invoke
display "Jexception: exception's content: "
errorMessage
else
display "!!!! theJavaException = null !!!"
end-if
invoke javasup "exceptionClear"
set address of lnkException to null
set theJavaException to null
exit program.