Re: Throwing user defined errors in RPG




David Herzog wrote:
I am trying to make use of the MONITOR op-code. I would like to be able to
call a procedure inside of a service program that throws an error when
something bad happens instead of returning an error (i.e. user input is
invalid). So, i would like to do something like this:

Monitor;
procedure1(value1);
procedure2(value2);
.
.
procedure10(value10);

On-Error;
// do something to handle the error
EndMon;


I could return an error code myself from the procedures like:

error = procedure1(value1);

and then check to see if there was an error returned but I like the idea
throwing the error from inside the procedure and letting the monitor handle
the error so the rest of my code does not get processed. This is how
exception handling in the java world works. The only errors that i have
been able to create are IBM defined errors (file related, divide by zero,
etc.). If there is no way to throw an error in RPG, is there a way to throw
an error in C or by using the C runtime libraries? If this is possible to
do, is there more overhead with throwing an error than having the return
value of the procedure be the error? I have searched all over the
internet for this and have not found anyone trying to do this.


The CEEHDLR API is the ILE way to catch exceptions.

http://www.itjungle.com/mpo/mpo081502-story05.html

The disadvantages to using CEEHDLR is it is a bit cumbersome to use. It
also slows down your code since you have to run the CEEHDLR and CEEHDLU
APIs everytime your monitored code is executed.

Some of the cumbersomeness can be overcome with procedures that handle
a lot of the housekeeping. The CPW overhead of using those APIs? Alas
we are at the mercy of IBM on that front. i5 CPW is very expensive.

-Steve

.