Thanks Scott
Scott Klement wrote:
Hi Robert,
The error codes that the MONITOR opcode can check for are documented here:
[1]
http://tinyurl.com/rpgstatus
Note that numbers 301 - 306 are Java related errors. In my experience,
just about every error that you receive from Java will be reported as
error code 301.
You cannot monitor for a particular Java exception like you do in Java.
You have to monitor for an RPG status code (such as 301) and that will
catch almost any Java exception that is sent to you.
After catching the error, you can use the QMHRCVPM API to receive the
message info that was sent in the RNX301 (RPG status 301) error message.
In parameter &6 of the message data, you should find the first 100
bytes of the Java exception. Unfortunately, it's only 100 bytes which
cuts many messages short.
So you'd do something like this:
Monitor;
fileOutputStream = new_FileOutputStream('filename');
On-Error 301;
QMHRCVPM(msginfo: %size(msginfo): 'RCVM0100': '*' 0
'*PRV': msgkey: 0: '*SAME': kaboom );
javaError = %subst(msginfo.msgdta:48:100);
Endmon;
So that's one approach, and it has it's limitations, but it might be the
easiest solution for you. The other possibility is to call the JNI API
directly. That's what RPG does under the covers, it calls the JNI API.
When it receives an error, it retrieves the exception and converts it
to an RNX0301 error.
You could call the JNI APIs directly yourself. Then you could handle
the exceptions any way you want to.
Robert Rogerson wrote:
I've checked the ILE RPG Programmers Guide, this list's archives and
various Google searches but I have been unable to find the answer.
My question is if RPG can catch thrown errors when calling java
methods/classes.
For example, in java if I code
[java code]
try {
new FileOutputStream("mydirectory$HelloWorld.pdf");
} catch (IOException ioe) {
System.err.println(ioe.getMessage());
}
[/java]
Since FileOutputStream throws FileNotFoundException and the directory is
invalid control will be passed to the catch code.
How do I do the same in RPG?
My thought is something similiar to
[RPG]
Monitor;
fileOutputStream =
new_FileOutputStream("mydirectory$HelloWorld.pdf");
On-Error (what do I check)
// handle the error
Endmon;
[/RPG]
If anyone knows an article or can explain how to handle exceptions it
would be greatly appreciated,
Robert Rogerson
References
Visible links
1.
http://tinyurl.com/rpgstatus
As an Amazon Associate we earn from qualifying purchases.