Class-based exception handling is based on exception classes. Exception classes can be defined by the user with the Exception Builder in the ABAP Workbench. A series of predefined exception classes is also available. In an exception situation, an exception is represented by an exception object, in other words, by an instance of an exception class. The attributes of an exception object may contain information on the error situation. All exception classes are part of an inheritance hierarchy with a common superclass, CX_ROOT.
The use of class-based exceptions is not restricted to ABAP Objects. On the contrary, class-based exceptions are designed to replace the previous concepts. Class-based exceptions can, therefore, be raised and handled in all ABAP contexts (programs, processing blocks). In particular, all the previous catchable runtime errors can be handled as class-based exceptions.
Class-based exceptions are either raised by the ABAP statement RAISE EXCEPTION or by the ABAP runtime environment. If a class-based exception occurs, the system interrupts the normal program flow and tries to find a suitable handler. If it does not find a handler, a runtime error occurs.
Handlers are not only defined for the statements within a program but are defined for entire call sequences. Exceptions that are raised in procedures but are not handled in the procedure itself are forwarded to the caller. The caller can either handle the exception or forward it. To ensure that the caller of a procedure knows which exceptions may occur in a procedure, all the unhandled exceptions of the procedure must usually be listed in their interface after the RAISING interface parameter. This rule can be circumvented using specific exception classes.
Handlers are defined for one or more exception classes. To define handlers for all the subordinate classes of the exception classes, a superclass is specified. This enables entire groups of related exceptions to be handled.
Grouping self-defined and predefined exceptions on the basis of exception classes provides users with the option of raising all the exceptions themselves. It also offers the advantage of consistent error handling throughout the entire program flow. The ABAP syntax for class-based exceptions results in a clear distinction between normal program processing and error handling. The syntax check supports the programming of the exception handling as far as possible by identifying exceptions that have not been handled or forwarded.