Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Program Flow Logic →  Exception Handling →  Class-Based Exceptions →  Exception Classes 

Creating Exception Classes

Exception classes can be defined globally in Class Builder or locally in a program. The names of global exception classes are prefixed with CX_ or, in the case of exception classes created in customer systems, YCX_ or ZCX_. There is a set of predefined global exception classes, such as those prefixed with CX_SY_, whose exceptions are raised in exception situations in the runtime environment.

All exception classes inherit the following instance methods from CX_ROOT:

  • GET_TEXT and GET_LONGTEXT return the exception text (short text and long text) as return values of type string. These methods are defined in the interface IF_MESSAGE implemented in CX_ROOT and can be addressed using the identically named alias name for the class.
  • GET_SOURCE_POSITION returns the program name, the name of the include program if applicable, and the line number of the statement that raised the exception.

All exception classes inherit the following instance attributes from CX_ROOT:

  • TEXTID of type SCX_T100KEY for a key for the database table T100 or of the type SOTR_CONC for a key for OTR (Online Text Repository) (that defines the exception text). This is normally set by the constructor and evaluated using GET_TEXT.
  • PREVIOUS of reference type CX_ROOT, which can contain a reference to a previous exception. This is normally set by the constructor.
  • IS_RESUMABLE of type ABAP_BOOL. For exceptions that are raised with the statement RAISE RESUMABLE EXCEPTION, the attribute is set to the value "X" in a CATCH block with the addition BEFORE UNWIND. This shows (in this block) whether the exception can be resumed, that is, whether it is possible to leave a CATCH block with RESUME. The attribute is not set if a CATCH block does not have the addition BEFORE UNWIND. In other CATCH blocks, in CLEANUP blocks, or after TRY, the value of IS_RESUMABLE is undefined.

For global exception classes, Class Builder generates a non-modifiable instance constructor that has optional input parameters for all non-private attributes and that sets these attributes to the value of the input parameters. The ID of the required exception text can be passed to TEXTID. In the case of local exception classes, there are no special rules for the instance constructor.

Other versions: 7.31 | 7.40 | 7.54


Notes

  • Instances of exception classes are generally created when exceptions are raised, but can also be instantiated using CREATE OBJECT.

  • The instance constructor of an exception class should not raise any exceptions. However, if an exception is raised in the instance constructor after an exception was raised during instantiation of the exception class, and the exception cannot be handled there, this or (if propagation is unsuccessful) the exception CX_SY_NO_HANDLER replaces the exception originally raised.

  • Additional methods and attributes can be defined in exception classes, for example to transport additional information about an error situation to the handler. The user-defined attributes should be read-only (READ-ONLY).