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 that displays a certain 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

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. In the following window, select a transport request in order to handover your new class to another system.
    • Select the Choose from requests in which I am involved radio button to pick an already existing transport request.
    • Select the Create a new request radio button in order to generate a new transport request. In the Request description field, you can type further information.
    • Select the Enter a request number in order to add your class to an existing request. Choose the Browse... button if you want to select a request that has already been created by a certain user.
  7. 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. In addition, 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 adaption of the constructor code in the exception class.

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 Additional tabs are available in the source code editor of the exception class. For more information, see Creating ABAP Classes
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. For more information, see Adding Code Templates to an ABAP Exception Class