Like all control structures in ABAP Objects, you can nest TRY-ENDTRY structures to any depth. In particular, the TRY block, the CATCH block, and the CLEANUP block can contain complete TRY-ENDTRY structures themselves.
Specify any number of exception classes in the CATCH statement. In this way, you define an exception handler for all these exception classes and their subclasses.
Example Syntax for Handling Predefined Exceptions
You can access any other public component of the exception object during exception handling depending on the static type of the reference variable. In the example above, the reference variable is typed as REF TO CX_ROOT, which restricts access to those components defined in CX_ROOT. To access the more-specific components of the exception object, you need a more-specific type reference variable type. You can also use the superclass CX_SY_ARITHMETIC_ERROR and the super-superclass CX_DYNAMIC_CHECK to access the specific components of the exception object.
The ABAP keyword documentation for each statement lists the classes whose exceptions may occur when that statement is executed.
The figure shows an example of syntax for handling predefined exceptions.
To analyze the exception object in an exception handler, use the CATCH statement in the form CATCH ... INTO ... You have to specify a suitably typed object reference after the optional addition INTO. The reference can be a reference either to the exception class itself or to any of its superclasses. Just before the system executes CATCH block, the system fills the reference variable so that it points to the exception object describing the present error situation.
If the value range for data type I is exceeded in the calculation, the runtime system raises exception CX_SY_ARITHMETIC_OVERFLOW. This exception is handled in the implemented CATCH block. The reference to the appropriate instance is stored in data object GO_EXC in the example. The handler can access the instance’s exception text using the functional method GET_TEXT. The exception text is stored in the data object GV_TEXT with the type STRING and then displayed as an information message.
Class-Based Exceptions in the Debugger
If an exception is raised, the system displays name of the exception class in the Exception Raised field in debugging mode.
If a CATCH block catches the exception a success message displays. The pointer for the current statement then moves to this CATCH block.
Two buttons appear if an exception occurs. Use the buttons to analyze the exception object and to navigate to the point in the source code where the exception occurred respectively.
Hint: For performance reasons, the system does not actually create exception objects if the INTO addition is missing from the respective CATCH statement. In such cases, the Last Exception Object button normally does not appear.
To set the ABAP Debugger to always create the exception object, choose the respective option in the debugger settings.