ABAP - Keyword Documentation →  ABAP - Reference →  Program Flow Logic →  Exception Handling →  Class-Based Exceptions → 

TRY

Quick Reference

Syntax

TRY.
    [try_block]
  [CATCH [BEFORE UNWIND] cx_class1 cx_class2 ... [INTO oref].
    [catch_block]]
    ...
  [ CLEANUP [INTO oref].
    [cleanup_block]]
ENDTRY.

Effect

The statement TRY introduces a control structure with multiple statement blocks. The first statement block try_block is always executed, whereas a branching off to exactly one of the remaining statement blocks only occurs if a class-based exception is raised in try_block.

A TRY control structure defines the following statement blocks:

A TRY control structure invalidates the simultaneous use of the obsolete statement CATCH SYSTEM-EXCEPTIONS to handle catchable runtime errors in the current processing block.

Notes

Example

Division by zero in a TRY block. The relevant exception is caught with CATCH.

TRY.
    cl_demo_output=>display( 1 / 0 ).
  CATCH cx_sy_arithmetic_error INTO DATA(exc).
    cl_demo_output=>display( exc->get_text( ) ).
ENDTRY.

Executable Example

Exceptions, TRY



Continue
CATCH
RESUME
RETRY
CLEANUP
ENDTRY