Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

exceptions

Former Member
1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
426

Hi,

HI,

Catchable runtime errors are handled with CATCH SYSTEM-EXCEPTIONSusing the name of the runtime error. To detect semantically related runtime errors using a common name, they are combined into exception groups.

You can handle catchable runtime errors in an ABAP program using the following control statements:

CATCH SYSTEM-EXCEPTIONS exc1 = rc1 ... excn = rcn.

...

ENDCATCH

.

Check the sample code to handle the exceptions.

REPORT ZTEST.

PARAMETERS number TYPE i.

DATA: result TYPE p DECIMALS 2,

oref TYPE REF TO cx_root,

text TYPE string.

TRY.

IF ABS( number ) > 100.

RAISE EXCEPTION TYPE cx_demo_abs_too_large.

ENDIF.

PERFORM calculation USING number

CHANGING result

text.

CATCH cx_sy_arithmetic_error INTO oref.

text = oref->get_text( ).

CATCH cx_root INTO oref.

text = oref->get_text( ).

ENDTRY.

IF NOT text IS INITIAL.

WRITE / text.

ENDIF.

WRITE: / 'Final result:', result.

FORM calculation USING p_number LIKE number

CHANGING p_result LIKE result

p_text LIKE text

RAISING cx_sy_arithmetic_error.

DATA l_oref TYPE REF TO cx_root.

TRY.

p_result = 1 / p_number.

WRITE: / 'Result of division:', p_result.

p_result = SQRT( p_number ).

WRITE: / 'Result of square root:', p_result.

CATCH cx_sy_zerodivide INTO l_oref.

p_text = l_oref->get_text( ).

CLEANUP.

CLEAR p_result.

ENDTRY.

ENDFORM.

<b>Reward points</b>

Regards

1 REPLY 1
Read only

Former Member
0 Likes
427

Hi,

HI,

Catchable runtime errors are handled with CATCH SYSTEM-EXCEPTIONSusing the name of the runtime error. To detect semantically related runtime errors using a common name, they are combined into exception groups.

You can handle catchable runtime errors in an ABAP program using the following control statements:

CATCH SYSTEM-EXCEPTIONS exc1 = rc1 ... excn = rcn.

...

ENDCATCH

.

Check the sample code to handle the exceptions.

REPORT ZTEST.

PARAMETERS number TYPE i.

DATA: result TYPE p DECIMALS 2,

oref TYPE REF TO cx_root,

text TYPE string.

TRY.

IF ABS( number ) > 100.

RAISE EXCEPTION TYPE cx_demo_abs_too_large.

ENDIF.

PERFORM calculation USING number

CHANGING result

text.

CATCH cx_sy_arithmetic_error INTO oref.

text = oref->get_text( ).

CATCH cx_root INTO oref.

text = oref->get_text( ).

ENDTRY.

IF NOT text IS INITIAL.

WRITE / text.

ENDIF.

WRITE: / 'Final result:', result.

FORM calculation USING p_number LIKE number

CHANGING p_result LIKE result

p_text LIKE text

RAISING cx_sy_arithmetic_error.

DATA l_oref TYPE REF TO cx_root.

TRY.

p_result = 1 / p_number.

WRITE: / 'Result of division:', p_result.

p_result = SQRT( p_number ).

WRITE: / 'Result of square root:', p_result.

CATCH cx_sy_zerodivide INTO l_oref.

p_text = l_oref->get_text( ).

CLEANUP.

CLEAR p_result.

ENDTRY.

ENDFORM.

<b>Reward points</b>

Regards