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 and catch question

Former Member
0 Likes
1,007

HI,

i want to now what is the benefit of try and catch?

what i think until now is if between the stetment try and catch i get dump , the program won't crash ,

but i try it and i have dump between the try and catch sentence .

Regards

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
969

Hi,

dump would occur if you dont catch all the exceptions.

Cheers,

KD

Hi,

dump would occur if you dont catch all the exceptions.

Cheers,

KD

7 REPLIES 7
Read only

Former Member
0 Likes
970

Hi,

dump would occur if you dont catch all the exceptions.

Cheers,

KD

Read only

0 Likes
969

HI Krutiman

Thanks ,

from what u tell i have to catch all the scenarios,

assume i do a catch on casting and i do in the try block divide operation i have to write onother catch for divide by i.e. to write 2 catch commend after the try ?

Regards

Read only

0 Likes
969

Yes Ricardo.

You need to create a separte catch for this.

Thanks,

Chidnanand

Read only

0 Likes
969

Class CX_ROOT is the superclass for global exceptions. If you catch this, you should catch most exceptions; however the error messages you get may not be as helpful as those you would get from one of the more specific class based exceptions.

Read only

Former Member
0 Likes
969

Hi Ricardo,

The concept of Try and Catch is when ever any exception comesup and you want to handle by your program then you need to use the Try and Catch Statement.

Thanks,

Chidanand

Read only

Former Member
0 Likes
969

Check out the following code

It catched devide by zero error.


DATA: w_var TYPE i,
      text   TYPE string,
      oref   TYPE REF TO cx_root.

TRY.
    w_var = 10 / 0.
  CATCH cx_sy_arithmetic_error INTO oref.
    text = oref->get_text( ).
  CATCH cx_root INTO oref.
    text = oref->get_text( ).
ENDTRY.

WRITE / text.

Read only

Former Member
0 Likes
969

TRY and END TRY is used with the CATCH statement. These statements used to handle the Exceptions at the Runtime so the program will not go into the Dump.

What ever code we wrirter inside the Try ENDTRY block is handled for Exception.

Refer this link for detail explanation :

http://help.sap.com/saphelp_nw70/helpdata/en/a9/b8eef8fe9411d4b2ee0050dadfb92b/content.htm