[ABAP] OO: Lokale Exception-Klasse anlegen, auslösen und behandeln

* lokale Exception-Klasse, erbt von cx_static_check
CLASS lcx_my_exception DEFINITION INHERITING FROM cx_static_check FINAL CREATE PUBLIC.
  PUBLIC SECTION.

* eigener Konstruktor mit zus. Parameter field_info
    METHODS: constructor
      IMPORTING
        !textid    LIKE textid OPTIONAL
        !previous  LIKE previous OPTIONAL
        field_info TYPE string OPTIONAL.

* neue Methode
    METHODS:
      get_fieldinfo
        RETURNING VALUE(re_field_info) TYPE string.

  PRIVATE SECTION.
    DATA: gv_field_info TYPE string.
ENDCLASS.

CLASS lcx_my_exception IMPLEMENTATION.
  METHOD constructor.
    super->constructor( textid = textid
                        previous = previous ).

    gv_field_info = field_info.
  ENDMETHOD.

  METHOD get_fieldinfo.
    re_field_info = gv_field_info.
  ENDMETHOD.
ENDCLASS.

CLASS lcl_demo DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS:
      div
        IMPORTING i_val1        TYPE f
                  i_val2        TYPE f
        RETURNING VALUE(rv_ret) TYPE f
* Propagieren der Exception
        RAISING   lcx_my_exception.
ENDCLASS.

CLASS lcl_demo IMPLEMENTATION.
  METHOD div.
    IF i_val2 = '0.0'.
* Wenn durch 0.0 geteilt werden soll: Auslösen der lokalen Exception, zusätzlichen Parameter übergeben
      RAISE EXCEPTION TYPE lcx_my_exception
        EXPORTING
          field_info = 'Neue Feldinfo.'.
    ELSE.
      rv_ret = i_val1 / i_val2.
    ENDIF.
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  TRY.
* durch 0.0 teilen -> Exception wird ausgelöst
      WRITE: / lcl_demo=>div( i_val1 = '1.1'
                              i_val2 = '0.0' ).
* Abfangen der lokalen Exception
    CATCH lcx_my_exception INTO DATA(e_txt).
      WRITE: / e_txt->get_text( ).
* zusätzlichen Parameter holen
      WRITE: / e_txt->get_fieldinfo( ).
  ENDTRY.