ABAP Keyword Documentation → ABAP − Reference → Program Flow Logic → Control Structures → Branches → CASE TYPE OF
Case Distinction CASE TYPE OF for Exceptions
This example demonstrates the case distinction CASE TYPE OF
for exception classes.
Other versions:
7.31 | 7.40 | 7.54
Source Code
DATA number TYPE string.
out = cl_demo_output=>new( ).
cl_demo_input=>request( CHANGING field = number ).
TRY.
my_sqrt( number ).
CATCH cx_root INTO DATA(exc).
CASE TYPE OF exc.
WHEN TYPE cx_sy_arithmetic_error.
out->display( 'Arithmetic error' ).
WHEN TYPE cx_sy_conversion_error.
out->display( 'Conversion error' ).
WHEN OTHERS.
out->display( 'Other error' ).
ENDCASE.
ENDTRY.
Description
Non-specific exceptions of the superclass CX_DYNAMIC_CHECK can be propagated from a method my_sqrt
.
The actual exception class is determined from the calling method using the case distinction CASE TYPE OF
.