Application Development 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: 

Difference between CATCH system-exceptions and try catch endtry

Former Member
0 Kudos

Hi ,

Can anyone of you tell me why try catch endtry is a preferred way than catch system-exceptions.

Regards,

Aruna

3 REPLIES 3

Former Member
0 Kudos

This message was moderated.

uwe_schieferstein
Active Contributor
0 Kudos

Hello Aruna

One major disadvantage of CATCH SYSTEM-EXCEPTIONS is that exception can be captured only locally meaning just around the piece of coding which is framed by CATCH - ENDCATCH.

In contrast, using TRY - ENDTRY (i.e. class-based exceptions) you can propagate the exception through a chain of callers due to the fact that you either "THROW or CATCH" the exception.

Example: You may have hierarchy of caller where at the deepest level an exception may occurs but you want to handle this exception at the first hierarchy level

  • CALL method_level_1

    • CALL method_level_2

      • CALL method_level_3

        • CALL method_level_4 (exception can occur here)

Now you can do the following:

TRY.
  • CALL method_level_1

    • CALL method_level_2

      • CALL method_level_3

        • CALL method_level_4 (exception can occur here)

CATCH cx_sy_arithmetic_error INTO lo_error.  " lo_error is of TYPE REF TO <exception class>
ENDTRY.

If all four methods the exception class defined in their signature and method_level_4 does not catch the exception it will be propagated to the top calling program which facilitates exception handling.

This you cannot achieve using CATCH - ENDCATCH.

Regards

Uwe

narin_nandivada3
Active Contributor
0 Kudos

Hi,

Please check this thread

Hope this would help you.

Good luck

Narin