I expect the following program to output an error message (via WRITE), but actually it triggers the run time error UNCAUGHT_EXCEPTION (short dump) at the time of RAISE EXCEPTION TYPE:
REPORT.
CLASS lcx_exception DEFINITION INHERITING FROM cx_static_check.
ENDCLASS.
CLASS lcl_app DEFINITION.
PUBLIC SECTION.
METHODS main.
ENDCLASS.
CLASS lcl_app IMPLEMENTATION.
METHOD main.
RAISE EXCEPTION TYPE lcx_exception. "<===== HERE, run time error UNCAUGHT_EXCEPTION
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
TRY.
NEW lcl_app( )->main( ).
CATCH lcx_exception INTO DATA(ex).
WRITE: / 'Exception:', ex->get_text( ).
ENDTRY.
The solution is to add RAISING lcx_exception (eventually more exception classes may be listed here) to the method declaration, so that the exception is automatically propagated to the calling procedure (and caught, hopefully) when it occurs:
REPORT.
CLASS lcx_exception DEFINITION INHERITING FROM cx_static_check.
ENDCLASS.
CLASS lcl_app DEFINITION.
PUBLIC SECTION.
METHODS main RAISING lcx_exception. "<==================== HERE
ENDCLASS.
CLASS lcl_app IMPLEMENTATION.
METHOD main.
RAISE EXCEPTION TYPE lcx_exception.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
TRY.
NEW lcl_app( )->main( ).
CATCH lcx_exception INTO DATA(ex).
WRITE: / 'Exception:', ex->get_text( ).
ENDTRY.
Note that you can't list the exception classes which inherit from the root class CX_NO_CHECK, directly or indirectly, because these exceptions are propagated implicitly. Only exception classes inheriting from CX_STATIC_CHECK and CX_DYNAMIC_CHECK, directly or indirectly, need to be indicated after RAISING for being propagated. Those 2 root classes may also be indicated to propagate all exception classes.
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