Show TOC

Creating an Exception ClassLocate this document in the navigation structure

Context

Tip

You can create a global exception class when you need it for the first time, for example, when you are assigning exceptions in the method definition.

See also Creating Exceptions for Methods.

Procedure

  1. In the Repository Browser (transaction SE80), navigate to the package where you want to create an exception class.
  2. In the context menu of the package, choose Start of the navigation path Create Next navigation step Class Library Next navigation step Class End of the navigation path.
    The Create Class dialog box appears.
  3. In the Class Type group box, choose Exception Class.
  4. In the Class field, enter a name for the new class in accordance with the naming conventions.
    Note

    The prefix CX_ should be added to the names of all exception classes.

  5. In the Description field, enter a short description of the class.
  6. Enter the remaining basic data for the class:
    Option Description

    Superclass

    Enter the name of the direct superclass.

    Note

    Exception classes are derived from one of the predefined basic classes CX_STATIC_CHECK, CX_DYNAMIC_CHECK or CX_NO_CHECK. Depending on the position of the exception class within the class hierarchy, enter the appropriate class within this hierarchy or one of the predefined basic classes as a superclass. In the latter case, expand a new hierarchy tree.

    Instantiation

    • The Public option is selected by default. This means that each user can create instances of the particular class (with CREATE OBJECT).
    • The Protected option defines that only inherited classes or the relevant class itself can create instances of this class.
    • If you choose the Private option, only the relevant class itself can create its instances (only using its own method).
    • You can define an abstract class with the Abstract option. You cannot create an instance for this class. An abstract class can be used as a template for your subclasses. You can only access this class with your static attributes or your subclasses.

    Class Type

    If you assign the prefix CX_ to the name of the exception class, the class type Exception class is automatically selected. You must define one or more exception texts to an exception class. Exception texts can be stored as messages in the T100 database table or in the Online Text Repository (OTR).
    Recommendation

    SAP recommends using exception texts stored in T100 only. Texts from OTR are reserved for system exceptions provided by SAP.

    So that you can use exception texts from T100, the With messages of message classes as exception texts checkbox is selected by default. Unchecking this means that exception texts from OTR are used (not recommended).

    If you use exception texts stored in T100, the exception class automatically implements the IF_T100_DYN_MSG interface, which itself implements the IF_T100_MESSAGE interface. Both interfaces connect classes with messages.

    For more information, see the Related Information below.

    Final

    Specifies the development status of the object. Only objects and components with this status can have executable code. This class completes the inheritance hierarchy since a final class may not create any further subclasses.

  7. Choose Save.
  8. Enter the name of the package to which your class should belong.
  9. Choose Save.

Results

A new exception class is created. A class pool is generated for the new class if the Only modeled option was not activated.

In contrast to the situation with normal classes, you cannot create a method for an exception class. The Class Builder simply creates the constructor, but you can create attributes and maintain exception texts.