Get Example source ABAP code based on a different SAP table
Exceptions, TRY> This example demonstrates the TRY> control structure.
ABAP_SOURCE_CODE DEMO CL_DEMO_TRY
ABAP_DESCRIPTION
If the content of number> is greater than 100, the TRY> control structure of the compilation unit> raises an exception of the class CX_DEMO_ABS_TOO_LARGE> in the TRY> block. This exception is handled by the second CATCH > block of the same TRY> control structure, since the subclass of the most general exception is CX_ROOT>.
If the content of number> is 0, the runtime framework in the TRY> block of the TRY> control structure of the called method calculation> raises an exception of the predefined class CX_SY_ZERODIVIDE>. This is handled in the CATCH> block of the same TRY> control structure.
If the content of number> is a negative number, the runtime framework in the TRY> block of the TRY> control structure of the called method calculation> raises an exception of the predefined class CX_SY_ARG_OUT_OF_DOMAIN>. Since no handler is defined for this exception in this TRY> control structure, the exception is propagated from the method, which is made possible by the declaration of the superclass CX_SY_ARITHMETIC_ERROR> using RAISING> in the method interface. The CLEANUP> block of the inner TRY> control structure is executed first.
Any other exceptions are handled in the final CATCH> block of the TRY> control structure of the compilation unit, which catches all possible exceptions by specifying the most generic exception class CX_ROOT>. If, for example, CX_SY_ARG_OUT_OF_DOMAIN> or one of its superclasses was not declared in the method interface, the exception CX_SY_NO_HANDLER> would be raised and would be handled in the final CATCH> block.