Entering content frameCatchable Runtime Errors Locate the document in its SAP Library structure

Error situations in the runtime environment that were handled in the program were handled as catchable runtime errors up to Release 6.10. Catachable runtime errors are assigned to certain ABAP statements and are triggered by the runtime environment if errors are detected in an ABAP statement.

Catchable runtime errors are handled with CATCH SYSTEM-EXCEPTIONS using the name of the runtime error. To detect semantically related runtime errors using a common name, they are combined into exception groups.

You can handle catchable runtime errors in an ABAP program using the following control statements:

CATCH SYSTEM-EXCEPTIONS <exc1> = <rc 1> ... <exc n> = <rc n>.
  ...
ENDCATCH.

The expressions <exci> indicate either a catchable runtime error or the name of an exception group. The expressions <rc i> are numeric literals. If one of the specified runtime errors occurs between CATCH and ENDCATCH, the program does not terminate. Instead, the program jumps straight to the ENDCATCH statement. After ENDCATCH, the numeric literal <rc i> that you assigned to the runtime error is contained in the return code field SY-SUBRC. The contents of any fields that occur in the statement in which the error occurred cannot be guaranteed.

CATCH control structures are like IF structures, that is, you can nest them to any depth, but they must begin and end within the same processing block. Furthermore, CATCH control structures only catch runtime errors at the current call level, and not in any procedures that you call from within the CATCH … ENDCATCH block.

Since as of Release 6.10 exceptions are generally handled based on classes, each detectable runtime error is assigned to a defined exception class. The exception groups were assigned to abstract intermediate classes in the inheritance hierarchy of the assigned exception classes. The defined exception classes adhere to the naming convention CX_SY_ ..., for example CX_SY_ZERODIVIDE. The ABAP keyword documentation contains an overview of the hierarchy of the defined exception classes.

With the predefined exception classes, a catchable runtime error between the TRY ... ENDTRY statements can be detected with the CATCH statement, like all exceptions that can be handled. This is the preferred method. Parallel handling with TRY ... ENDTRY and CATCH ... ENDCATCH is not allowed within a processing block. No new catchable runtime errors are planned for the future. Instead, it is exceptions in ABAP statements will only be handled by assigning exception classes.

Example

REPORT demo_catch_endcatch.

DATA: result TYPE p DECIMALS 3,
      number TYPE i VALUE 11.

CATCH SYSTEM-EXCEPTIONS arithmetic_errors = 5.
  DO.
    number = number - 1.
    result = 1 / number.
    WRITE: / number, result.
ENDDO.
ENDCATCH.

SKIP.

IF sy-subrc = 5.
  WRITE / 'Division by zero!'.
ENDIF.

This program calculates the quotient of 1 and NUMBER ten times until the catchable runtime error BCD_ZERODIVIDE occurs. This runtime error belongs to the exception group ARITHMETIC_ERRORS, and is caught in the example using this class.

Leaving content frame