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?
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:
CX_STATIC_CHECK
have to be handled or propagated, otherwise the program is syntactically incorrectCX_DYNAMIC_CHECK
do not require handling or propagation, but will abort the program that does not handle or propagate the exceptionCX_NO_CHECK
will always be propagated automatically unless handledCatching 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With