SAP ABAP LANGUAGE EXCEPTIONS



Get Example source ABAP code based on a different SAP table
  



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 framework. Two types of exception exist:
Catchable exceptions, which are based on predefined exception classes.
Uncatchable exceptions, which directly produce runtime errors.
Each catchable exception is assigned to a runtime error that terminates the program if the exception is neither caught by using the CATCH statement with a suitable exception class nor propagated to a caller. The keyword documentation lists the type of exceptions that can be raised for each statement.
BEGIN_SECTION VERSION 5 OUT
For reasons of backward compatibility, catchable exceptions raised by many ABAP statements can be caught by using
TRY ... CATCH ... ENDTRY This is the recommended way.
CATCH SYSTEM-EXCEPTIONS ... ENDCATCH This statement is obsolete. To use it, the runtime error assigned to the exception class must be catchable itself.
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.
END_SECTION VERSION 5 OUT

ABAP_EXAMPLE_VX5
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:
ABEXA 01603
ABAP_EXAMPLE_END

ABAP_EXAMPLE_VX5
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. Therefore, the exception can be handled as follows (the ERR_TEXT variable is passed the text Division by zero.):
ABEXA 01604
ABAP_EXAMPLE_END
BEGIN_SECTION VERSION 5 OUT



Example ABAP Coding

Handling exceptions as catchable runtime errors.
Since the runtime error COMPUTE_INT_ZERODIVIDE is catchable and assigned to the exception group ARITHMETIC_ERRORS, it can also be handled using the obsolete statement CATCH SYSTEM-EXCEPTIONS.
ABEXA 01605
ABAP_EXAMPLE_END
END_SECTION VERSION 5 OUT