Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Program Flow Logic →  Exception Handling 

Exceptions in ABAP Statements

Error situations that occur during the execution of an ABAP statement raise exceptions. These exceptions are fully integrated into the exception concept and are raised by the runtime environment. Two types of exception exist:

Each handleable exception is associated with a runtime error. The program terminates with this error if the exception is neither handled nor propagated to a caller. The keyword documentation lists the type of exceptions that can be raised for each statement.

For reasons of backward compatibility, handleable exceptions raised by many ABAP statements can be caught by using both TRY ... ENDTRY and the obsolete statement CATCH SYSTEM-EXCEPTIONS ... ENDCATCH. For this to be possible, the runtime error assigned to the exception class must be catchable. Within processing blocks, the two mechanisms prevent each other from handling exceptions. It is advisable to catch an exception between TRY ... ENDTRY using CATCH or to use the RAISING addition in the definition of the interface to propagate it to the caller. Catching exceptions using CATCH SYSTEM-EXCEPTIONS is no longer recommended.

Other versions: 7.31 | 7.40 | 7.54


Unhandled Exception

The following program lines produce the runtime error COMPUTE_INT_ZERODIVIDE because division by zero is invalid and this exception situation is not handled:

DATA result TYPE i.
result = 1 / 0.

Handling Exceptions Using Exception Classes

The above exception is represented by the exception class CX_SY_ZERODIVIDE, which is a subclass of the exception class CX_SY_ARITHMETIC_ERROR. This means that the exception can be handled as follows (the ERR_TEXT variable is passed the text 'Division by zero.'):

DATA myref TYPE REF TO cx_sy_arithmetic_error.
DATA err_text TYPE string.
DATA result TYPE i.
    result = 1 / 0.
  CATCH cx_sy_arithmetic_error INTO myref.
    err_text = myref->get_text( ).

Handling Exceptions as Catchable Runtime Errors

The runtime error COMPUTE_INT_ZERODIVIDE is catchable and assigned to the exception group ARITHMETIC_ERRORS, which means it can also be handled using the obsolete statement CATCH SYSTEM-EXCEPTIONS.

DATA result TYPE i.
CATCH SYSTEM-EXCEPTIONS arithmetic_errors = 4.
  result = 1 / 0.
IF sy-subrc = 4.


Exception Classes for ABAP Statements