Show TOC

 Class-Based ExceptionsLocate this document in the navigation structure

Class-based exceptions are realized as instances of exception classes. Exception classes are either globally predefined in the system or can be defined by the user globally or locally. Class-based exceptions are triggered either by the ABAP runtime environment or by a program.

Exception situations that are recognized by the system and whose causes can be handled in the program trigger predefined class-based exceptions. This happens especially in all situations in which catchable runtime errors were triggered before class-based exceptions were introduced.

The exceptions of all exception classes that are visible in a program can be triggered with a RAISE EXCEPTION.

Class-based exceptions can be declared in the interface of procedures. For local procedures, you use the addition RAISING of the statements METHODS and FORM for it. In the Class and Function Builder, you select exception classes when defining exceptions in the interface. The declared exceptions can occur at the call position of a procedure if the exception is not treated in the procedure.

When an exception is triggered, an exception object is created whose attributes contain information about the error situation. A class-based exception can be treated in a TRY control structure. Within the TRY, a protected area is defined whose exceptions can be treated in subsequent CATCH blocks. The RETRY statement enables you to repeat a complete TRY block after an exception.

Because all exception classes are subclasses of common superclasses, the related exceptions can also be treated by treating the respective superclass. The system propagates the exception object or the class-based exception until the exception is treated or an interface is violated.

There are two different cases for exception handling:

  • The context in which the exception was raised is deleted completely before or after handling. This removes all procedures from the memory (and also their local data, which was called from the handler context and which caused the exception); handling is resumed depending on how the handler is exited.
  • The context in which the exception was raised is retained and the program is resumed after the statement that raised the exception.
    Note

    A prerequisite for the second case are resumable exceptions. These exceptions must be raised with the RESUMABLE addition of the RAISE EXCEPTION statement and declared using the RESUMABLE addition in the interface of the procedures from which they were propagated. The RESUME statement is used to resume the program.

For more information, see the ABAP Keyword Documentation under Class-Based Exceptions.