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, which is used in a
CATCH block or CLEANUP block to show whether the exception is
resumable, that
is whether a CATCH block can be exited using RESUME.
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.
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).