Skip to main content

This article describes Java constructor throwing exception issue when calling Java from OO COBOL.

Problem:

Before the delivery of Net Express 5.1 Websync2, it was not possible for an OO COBOL program to consume a Java class's constructor that throws an exception. This has been fixed in Net Express 5.1 Websync2.

The COBOL Code which creates an instance of JAVA class SimpleClass appears below. It is also attached to this article.

ExceptionCatcher.cbl
$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.
&

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"
&

display "COBOL: Exception excepted in constructor"
stop run.

entry "Jexception" using lnkException.

display "Jexception: Exception occured"
invoke lnkException "display"
invoke javasup "exceptionOccurred"
returning theJavaException
IF theJavaException not = null
display "Jexception: retrieve exception's content"
invoke theJavaException "printStackTrace"
invoke theJavaException "toString"
returning aStr
call "strlen" using aStr returning aStrlength
display "Jexception: exception's content: "
aStr(1:aStrlength)
else
display "!!!! theJavaException = null !!!"
END-IF

invoke javasup "exceptionClear"
set address of lnkException to null
set theJavaException to null
exit program.
.

. &

SimpleClass.java :
import java.lang.* ;
public class SimpleClass {
public SimpleClass() {
}

public SimpleClass(int i ) throws Exception{
String s = "\\nJAVA: Test error in Class's constructor\\n";
System.out.println(s);
Exception e = new Exception (s);
throw e;
}

public void TestException() throws Exception
{
Exception e = new Exception ("Test error" );
throw e;
}
}

Resolution:

Install Net Express Websync2 update.

Old KB# 14174

This article describes Java constructor throwing exception issue when calling Java from OO COBOL.

Problem:

Before the delivery of Net Express 5.1 Websync2, it was not possible for an OO COBOL program to consume a Java class's constructor that throws an exception. This has been fixed in Net Express 5.1 Websync2.

The COBOL Code which creates an instance of JAVA class SimpleClass appears below. It is also attached to this article.

ExceptionCatcher.cbl
$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.
&

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"
&

display "COBOL: Exception excepted in constructor"
stop run.

entry "Jexception" using lnkException.

display "Jexception: Exception occured"
invoke lnkException "display"
invoke javasup "exceptionOccurred"
returning theJavaException
IF theJavaException not = null
display "Jexception: retrieve exception's content"
invoke theJavaException "printStackTrace"
invoke theJavaException "toString"
returning aStr
call "strlen" using aStr returning aStrlength
display "Jexception: exception's content: "
aStr(1:aStrlength)
else
display "!!!! theJavaException = null !!!"
END-IF

invoke javasup "exceptionClear"
set address of lnkException to null
set theJavaException to null
exit program.
.

. &

SimpleClass.java :
import java.lang.* ;
public class SimpleClass {
public SimpleClass() {
}

public SimpleClass(int i ) throws Exception{
String s = "\\nJAVA: Test error in Class's constructor\\n";
System.out.println(s);
Exception e = new Exception (s);
throw e;
}

public void TestException() throws Exception
{
Exception e = new Exception ("Test error" );
throw e;
}
}

Resolution:

Install Net Express Websync2 update.

Old KB# 14174

This wiki-page is unusable!

The Code is incompletely and there is no demo file attached to this article!