09-25-2008 1:00 PM
Hi ,
Can anyone of you tell me why try catch endtry is a preferred way than catch system-exceptions.
Regards,
Aruna
09-25-2008 1:05 PM
09-25-2008 7:42 PM
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
09-26-2008 8:33 AM