anthyiaconsulting

ABAP Tutorial

2 Exceptions

When a program is executed, errors may arise; these errors trigger an exception (aka raise an exception).

  • 1. The ABAP runtime environment or

  • 2. the code

may trigger an exception.

If the exception is not dealt with by a handler, a runtime error occurs. Examples of exceptions include arithmetic overflows, memory consumption problems, or a syntax error in a SQL statement.

a Class-based exceptions

The RAISE EXCEPTION statement raises an exception. This statement may be used in the method of a class. The syntax of the RAISE statement is as follows:

1    RAISE EXCEPTION type zc01_db_exception.

Listing III.4: How to raise an exception in your code

Class-based exceptions are not a part of the method call, but rather follow the following pattern.

1     TRY.
2            *...execute standard program flow here...
3     CATCH zc01_db_exception INTO EXCEPTION_OBJECT.
4            *...react to the exception here...
5     ENDTRY.

Listing III.5: Basic structure of Exceptions

The CATCH statement specifies the exception class. The CATCH block is an exception handler. When the exception specified within the TRY block occurs, the code after the CATCH statement is executed

b Global exceptions