Manually throw an exception?

D.Cook

Member
OK it seems like a standard function, but I can't actually find a way to throw an exception! In the documentation it is an option for DO ON ERROR UNDO, THROW ... but what if I want to throw an exception based on a condition?
Am I missing something?
 

RealHeavyDude

Well-Known Member
You can only throw an exception as option with either

  • ON ERROR phrase
  • ROUTINE-LEVEL ON ERROR UNDO
  • UNDO statement

As the ABL is still block oriented you can't just throw an exception as you would for example in Java which has a throw statement. Personally I would like to be able to be more "free" in throwing exceptions and I also would like the exception handling to be more intuitive. All the exception handling is intermingled with the "old" block behavior and it's rather easy to generate code that eats exceptions ( but that's IMHO, of course ). You need to be very careful to not "break" the catch chain ...

Heavy Regards, RealHeavyDude.
 

KrisM

Member
I think that throwing exceptions with the undo statement is adequate enough.
But that is just my opinion.
 

RealHeavyDude

Well-Known Member
I don't think so because undo has more to it: It means that anything that is undo-able up to the next outer block with automatic error handling will be undone too. And, that might not be suitable in every case. If it is not appropriate then you need to code a horrible workaround - to say the least.

Heavy Regards, RealHeavyDude.
 

D.Cook

Member
I see, so "UNDO, THROW e" will throw an exception, but also run the undo logic for the current block. Considering that normally an error will also initiate an undo of the block, using the UNDO statement seems pretty logical and safe to me.
Especially considering our programming practice is to always declare variables as NO-UNDO so they wouldn't be affected anyway.
 

RealHeavyDude

Well-Known Member
Just to be clear: Most of the time UNDO, THROW will be sufficient but I've run into a scenario where the implicit UNDO caused me some headaches - that is all what I've said, it might not be sufficient all the time and that is why I would like to have more freedom in throwing exceptions and handling them.

Heavy Regards, RealHeavyDude.
 
Top