Beispiel zur klassenbasierten Ausnahmebehandlung

*&---------------------------------------------------------------------*
*& Report  ZZ_40_TRY
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
 
REPORT  zz_40_try.
 
PARAMETERS number TYPE i.
 
DATA result TYPE p DECIMALS 2.
DATA oref TYPE REF TO cx_root.
DATA text TYPE string.
 
START-OF-SELECTION.
 
  WRITE: / 'Testing divison and Sqare root with', number.
  ULINE.
  TRY.
      result =  1 / number.
      WRITE: / 'Result of division:', result.
      result = SQRT( number ).
      WRITE: / 'Result of square root:', result.
    CATCH cx_sy_zerodivide INTO oref.
      text = oref->get_text( ).
    CATCH cx_sy_arithmetic_error INTO oref.
      text = oref->get_text( ).
  ENDTRY.
  IF NOT text IS INITIAL.
    WRITE / text.
  ENDIF.