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

TRY to CATCH a system exception

rainer_hbenthal
Active Contributor
0 Likes
1,993

Hi,

in a class, i have two methods, let me call them A and B.

method A is calling method B. In method B an exception CX_SY_CONVERSION_NO_NUMBER may occur. So the code is something like this in method A:



TRY.
  me->B( par ).

  catch CX_SY_CONVERSION_NO_NUMBER.
    do_some_error_handling

ENDTRY.

Stll the program abends with an uncaught exception CX_SY_CONVERSION_NO_NUMBER which occured in method B. Why isnt this be caught in method A? How can i handle this in method A with try and catch?

1 ACCEPTED SOLUTION
Read only

varma_narayana
Active Contributor
0 Likes
1,150

Hi..

Here the Exception is triggered by method B. So u must have to code like this.

in the Method B Definition you must add the addition

RAISING CX_SY_CONVERSION_NO_NUMBER as a parameter. Then this code works.

TRY.

me->B( par ).

catch CX_SY_CONVERSION_NO_NUMBER.

do_some_error_handling

ENDTRY.

REWARD IF HELPFUL.

Hi,

in a class, i have two methods, let me call them A and B.

method A is calling method B. In method B an exception CX_SY_CONVERSION_NO_NUMBER may occur. So the code is something like this in method A:



TRY.
  me->B( par ).

  catch CX_SY_CONVERSION_NO_NUMBER.
    do_some_error_handling

ENDTRY.

Stll the program abends with an uncaught exception CX_SY_CONVERSION_NO_NUMBER which occured in method B. Why isnt this be caught in method A? How can i handle this in method A with try and catch?

6 REPLIES 6
Read only

Former Member
0 Likes
1,150

Hi,

Strange - have you checked whether your CATCH block is actually executed? If so, are you shure that your exception code doesn't raise an exception itself?

Regards, Joerg

Read only

0 Likes
1,150

No, the catch isnt executed, the abend says thats happening when i'm assigning 'A' to a decimal varbiable. Of course this is not possible, but i want to handle this myself without an abend. And yes, the exception is exactly the same i wrote in my catch expression and which finally abends the program.

Read only

Former Member
0 Likes
1,150

Hello Rainer,

To make sure everything is caught catch the exception cx_root.

If that doesn't help you could do the following:

don't use TRY ... ENDTRY.

But use CATCH ... ENDCATCH:


CATCH SYSTEM-EXCEPTIONS.
  me->B( par ).
  if sy-subrc <> 0.
    do_some_error_handling.
  endif.
ENDCATCH.

best regards

Sven

Read only

0 Likes
1,150

If i'm doing it like this:

try.

tmp = 'A'.

me->convert( parameter ).

catch cx....

endtry.

the exception is caught. I thought that calling a methof/function where an exception occured is caught too, but is this not true? Are systemexceptions are being handled in the same scope?

Read only

varma_narayana
Active Contributor
0 Likes
1,151

Hi..

Here the Exception is triggered by method B. So u must have to code like this.

in the Method B Definition you must add the addition

RAISING CX_SY_CONVERSION_NO_NUMBER as a parameter. Then this code works.

TRY.

me->B( par ).

catch CX_SY_CONVERSION_NO_NUMBER.

do_some_error_handling

ENDTRY.

REWARD IF HELPFUL.

Read only

0 Likes
1,150

Hi thanks, i really have forgotten the raising clause....