× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi Robert,

The error codes that the MONITOR opcode can check for are documented here:
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


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.