Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do exceptions propagate automatically?

Tags:

exception

abap

I'm relatively new to ABAP development and have more experience in Java and similar languages. In Java, any exception that is thrown and not caught is automatically propagated up the call chain so that you can decide how to handle it at the highest (user-facing) level of your program.

I would now like to do the same thing in some of my ABAP reports where I use class methods or function calls, some of which go several levels deep. Especially for reports meant to run in a job, I want to make sure that all exceptions are handled. This works fine as long as you specify each possible exception in the raising or exception block of a method. I realise however that I regularly use functions or methods that will raise a certain exception that I don't explicitly mention in the definition of the method calling them. I was under the assumption that these would simply propagate up but a section of the ABAP documentation seems to indicate that this is not the case.

My question now is if it makes sense to use a TRY [...] CATCH cx_root block in my report. While this correctly catches any exceptions thrown in the block that don't have a specific CATCH statement, the documentation seems to suggest that exceptions not specifically mentioned in a method definition will throw a short dump for an unhandled exception rather than moving up the call chain to see if the exception is handled there. Can anyone confirm this?

like image 830
Lilienthal Avatar asked Jan 22 '14 09:01

Lilienthal


1 Answers

It depends - in this case on the exception class hierarchy. You cannot subclass CX_ROOT directly, you have to use one of its direct subclasses:

  • subclasses of CX_STATIC_CHECK have to be handled or propagated, otherwise the program is syntactically incorrect
  • subclasses of CX_DYNAMIC_CHECK do not require handling or propagation, but will abort the program that does not handle or propagate the exception
  • subclasses of CX_NO_CHECK will always be propagated automatically unless handled

Catching CX_ROOT inside the application is usually a bad idea, unless you really know what you're doing. Don't try to catch stuff you can't handle.

like image 152
vwegert Avatar answered Sep 23 '22 03:09

vwegert