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

General exception for try and catch.

Former Member
0 Likes
7,364

Hi all,

I know TRY and CATCH in Java.

Lets say in Java, if I know the particular SQL error then it will throw exception into SQLException. For general or unknown exception it will throw into Exception.

What should I use for ABAP programming?

Please use above example to show me please.

Thank you very much.

1 ACCEPTED SOLUTION
Read only

Sm1tje
Active Contributor
0 Likes
3,464

If you know which exception will be thrown you can use this. But if you are not really sure and you haven't been able to find out it is possible to use the root exception (main exception of which all other exceptions are inherited).

Main exception: cx_root.

data:lr_error type ref to cx_root.

try.

catch cx_root into lr_error.

endtry.

Other exceptions.

data:lr_error type ref to particular exception.

try.

catch particular exception into lr_error.

endtry.

Hi all,

I know TRY and CATCH in Java.

Lets say in Java, if I know the particular SQL error then it will throw exception into SQLException. For general or unknown exception it will throw into Exception.

What should I use for ABAP programming?

Please use above example to show me please.

Thank you very much.

4 REPLIES 4
Read only

Sm1tje
Active Contributor
0 Likes
3,465

If you know which exception will be thrown you can use this. But if you are not really sure and you haven't been able to find out it is possible to use the root exception (main exception of which all other exceptions are inherited).

Main exception: cx_root.

data:lr_error type ref to cx_root.

try.

catch cx_root into lr_error.

endtry.

Other exceptions.

data:lr_error type ref to particular exception.

try.

catch particular exception into lr_error.

endtry.

Read only

Former Member
0 Likes
3,464

Hi Micky Oestreich,

Thanks so much for your prompt replied.

It really solved my problem and doubts.

Thanks so much.

Read only

Sm1tje
Active Contributor
0 Likes
3,464

Just to be complete:

Maybe not all SQL errors can be caught by the class based exceptions. In some cases you might have to use the traditional way of catching exceptions with statement:

CATCH EXCEPTIONS .... (Use F1 help for exact syntax).

Read only

Former Member
0 Likes
3,464

Thanks again for your advise.

I will keep that in mind.