Catch

GregTomkins

Active Member
10.2B HPUX

I was experimenting with 'catch' a little. It seems like it only works within a .P, eg., if x.p runs y.p with a catch block and y.p causes an error, x.p doesn't see it, eg. in other words, the catch doesn't encompass subprocedures. If true, this makes it not very useful IMO.

Am I misunderstanding something? The documentation doesn't seem to cover this (that I could find). The documentation of ROUTINE-LEVEL implies that this is the case, though.

Anecdotally, it seems like amongst the posters here and the cacophony of OO enthusiasm, the topic of 'catch' is rarely mentioned. (I realize 'catch' isn't OO specific, I mention them together in the sense that they are both relatively recent additions, and both likely motivated by Java-catchup).
 

TheMadDBA

Active Member
Does your .p start with ROUTINE-LEVEL ON ERROR UNDO, THROW?

That should make a lot of blocks throw errors back to the top level. Do you have a simple example that isn't working for you?
 

GregTomkins

Active Member
The way I read the doc, ROUTINE-LEVEL is about IP's within a .P; not .P's calling each other. Here's a trivial example that seems not to work. I think it should suppress the non-existent record error and instead run the MESSAGE. It does if you do the same FIND from within tc1.p, but but when you do so in the subprocedure.

/* tc1.p */
ROUTINE-LEVEL ON ERROR UNDO, THROW.
RUN tc2.p.
CATCH v AS Progress.Lang.SysError:
MESSAGE "error".
END.

/* tc2.p */
FIND mfclac "FOO". /* doesn't exist */
 

RealHeavyDude

Well-Known Member
Unless you code a do on error block in tc2.p the error cause by the find will not be catched by any structured error handling. In your case the default error handling of the procedure block will kick in. You need to code something like this:
Code:
do on error undo, leave:
 
  find ... /* Causes error */
 
  catch anyError as Progress.Lang.Error:
 
    / * Your error handling here ... */
    delete object anyError.
 
  end catch.
 
end.

Heavy Regards, RealHeavyDude.
 

Cringer

ProgressTalk.com Moderator
Staff member
That's good info RHD :)
Whilst we're on the subject, what's the difference between ROUTINE-LEVEL and BLOCK-LEVEL (introduced in 11.x I believe)?
 

Stefan

Well-Known Member
Also note that there is a startup parameter to automatically add routine-level or block level (when on 11.x) when compiling.

routine-level will not add anything to a block, an important type of block being for each.

Meaning you need to add on error undo, throw to every for each. block-level removes requirement.
 

Stefan

Well-Known Member
Definitely - unless you want to add on error undo, throw to every block to ensure your error bubbles up to the top of the stack automatically.
 

Cringer

ProgressTalk.com Moderator
Staff member
I'm on 11.2.1. Do later versions of PDSOE allow you to add BLOCK-LEVEL as standard to a procedure/class, or is it still just ROUTINE-LEVEL?
 

GregTomkins

Active Member
Aha!, BLOCK-LEVEL looks like it makes CATCH pretty useful ( and Java-like).

Starts in 11.2, unfortunately; all of us will be in the ground long before my shop is on 11.2, but at least it's a theoretical possibility ;)
 
Top