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: 

which Exception Handling design is more make sense?

Former Member
0 Kudos
172

question : is it necessary for caller to catch all the exceptions and re-raise them if the caller cannot handle it?

Plan A. code brief


*definition
METHODS meth_a
   RAISING ex_b.
METHODS meth_c
   RASING ex_d.
*implementation
METHOD c
  TRY.
    CALL METHOD me->meth_a.
    CATCH ex_b into l_ex_b.
      "suppose meth_c cannot handle the situation, just envelope and reraise it
      RAISE EXCEPTION TYPE ex_d
        EXPORTING
          previous = l_ex_b
          textid = 'new text id to explain why meth_c failed'
  ENDTRY.
ENDMETHOD.

Plan B. code brief


*definition
METHODS meth_a
   RAISING ex_b.
METHODS meth_c
   RASING ex_b ex_e. " declare 2 exception
*implementation
METHOD c
    CALL METHOD me->meth_a.
    "....
    RAISE EXCEPTION TYPE ex_e. " no relation to ex_b
ENDMETHOD.

the second implementation saves more labor, but I don't know if it will lost some exception-chain information?

is it necessary to do as first implementaion? for each exception handler?

thanks and regards,

1 ACCEPTED SOLUTION

amit_khare
Active Contributor
0 Kudos
56

No, its not necessary to catch all exceptions, if the user is sure of not getting them.

But as a good practice to avoid any confusion or unforeseen dumps one should handle all.

Its not just about labor its about delivering a good code.

Regards,

Amit

Edited by: Amit Khare on Dec 19, 2007 6:01 AM

3 REPLIES 3

amit_khare
Active Contributor
0 Kudos
57

No, its not necessary to catch all exceptions, if the user is sure of not getting them.

But as a good practice to avoid any confusion or unforeseen dumps one should handle all.

Its not just about labor its about delivering a good code.

Regards,

Amit

Edited by: Amit Khare on Dec 19, 2007 6:01 AM

0 Kudos
56

thanks, so quickly.

0 Kudos
56

You are welcome.