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-EXCEPTIONSusing 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:
SYSTEM-EXCEPTIONS exc1 = rc1 ... excn =
The expressions exc1 … excn indicate either a catchable runtime error or the name of an exception class. The expressions rc1 … rcn are numeric literals. If one of the specified runtime errors occurs betweenCATCHand ENDCATCH, the program does not terminate. Instead, the program jumps straight to the ENDCATCH statement. After ENDCATCH, the numeric literal rc1 … rcn 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 after ENDCATCH.
CATCH control structures are like IFstructures, 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 predefined 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. For an overview of the hierarchy of the predefined exception classes, use the ABAP keyword documentation.
With the predefined exception classes, a catchable runtime error between the TRY ... ENDTRY statements can be detected with the CATCHstatement, 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.
DATA: result TYPE p DECIMALS 3,
number TYPE i VALUE 11.
CATCH SYSTEM-EXCEPTIONS arithmetic_errors = 5.
number = number - 1.
result = 1 / number.
WRITE: / number, result.
IF sy-subrc = 5.
WRITE / 'Division by zero!'.
The program calculates the quotients tens time from 1 and number until the runtime error BCD_ZERODIVIDE occurs. This belongs to the exception group ARITHMETIC_ERRORS, and is caught in the example using this class.