Show TOC

Creating ABAP Exception ClassesLocate this document in the navigation structure

Context

You create an exception class to build a template for objects in order to handle a class-based error. In this case, a certain message is displayed that is defined with an exception ID, which in turn displays a T100 message.

Note An ABAP exception class is automatically created whenever one of the following superclasses is added to an ABAP class:
  • CX_STATIC_CHECK
  • CX_DYNAMIC_CHECK
  • CX_NO_CHECK
Note

In SAP NetWeaver 7.5 SP00 and higher, the exception class implements the system interface IF_T100_DYN_MSG. It extends and covers all functionality of the system interface IF_T100_MESSAGE that is implemented in the previous SAP NetWeaver releases.

The system IF_T100_MESSAGE is used to statically assign specific messages to an exception class that defines the semantics of the exception. The system interface IF_T100_DYN_MSG allows you to assign arbitrary messages of message classes to the exception by using the statement RAISE EXCEPTION ... MESSAGE ... at runtime.

Procedure

  1. In the Project Explorer, select the relevant package node.
  2. Open the context menu and choose Start of the navigation path New Next navigation step ABAP Class End of the navigation path to launch the creation wizard.
  3. Specify the Project and Package properties of the class to be created.
  4. Enter the Name and Description for the class to be created and choose Next.
    Note Use [Your Prefix]CX_[Your Class Name] as the name.
  5. In the Superclass field, enter one name of the following superclasses:
    • CX_STATIC_CHECK
    • CX_DYNAMIC_CHECK
    • CX_NO_CHECK

    When editing the superclass, you can avail of the content assistant functionality by pressing Ctrl + Space.

    Creation of an exception class with CX_STATIC_CHECK as superclass
    Figure 1: Creation of an exception class with CX_STATIC_CHECK as superclass
  6. Choose Next.
  7. In the following window, select a transport request in order to hand over your new class to another system.
  8. Start the creation with Finish.

Results

The exception class is created just like a regular ABAP class. Therefore, the back-end system creates an inactive version of a class pool in the selected package that is stored in the class library of the repository. In the Project Explorer, the new class is added to the Source Library of the corresponding package node.

In the source code editor, the initially generated source code is displayed and ready for editing.

Here, the constructor method of the superclass that is declared in the public section is added. It contains generated code that reflects the current state of the class hierarchy. Any further changes to the superclass constructor or the class itself will not trigger automatic adaptation of the constructor code in the exception class. This behavior is ensured by the ##ADT_SUPPRESS_GENERATION pragma that is added where the implementation of the constructor method begins.

The constructor code can be only regenerated by executing the cleanup utility in the back end. As a result, your own code in the constructor method will be lost in ADT after the cleanup.

Note In the exception class, you can add a code template to the definition part. This enables you to reuse source code in order to display a specific T100 message.