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: 

Catching abap exception

Former Member
0 Kudos

Hi Friends,

I'm testing a function and for that I'm forcing dumps, and catching exceptions. Divisions by zero is one of the examples.

For division by zero I'm able to catch it with an c_sy_no_handler exception, but I've another example which I'm not being able to catch it.

I'm sendind an message e001(zisa), which will exit automatically from the function module. Am I able to catch that message? Meaning, can I catch it and treat it, instead of the system exiting the function and showing the corresponding message?

1 ACCEPTED SOLUTION

Former Member
0 Kudos

you can try CATCH statement to catch the exception.

6 REPLIES 6

Former Member
0 Kudos

you can try CATCH statement to catch the exception.

0 Kudos

Hi Venkat,

I've done that for the divide by zero exception. And I've tried for this as well, but cx_sy_no_handler doesn't catch it. I've looked for another cx_* but I was not able to find it. Do you know any? or any method?

Former Member
0 Kudos

Try to use command RAISE or MESSAGE ... RAISING...

0 Kudos

Hi,

If you want to show an error message and also want to catch it raise an exception along with the message.

Ex MESSAGE e001(zisa) raising <EXCEPTION>. Declare this exception in the exception tab of the Function module.

You can also use ERROR-MESSAGE if you just want to catch the message with out raisning the exception.

Regards,

Sesh

0 Kudos

Hi Seshatalpasai,

I tried to MESSAGE e001(zisa) raising cx_application_fault, where I defined the exception on the function module exceptions, but I'm not able to activate it. I get:

"you cannot use MESSAGE RAISING together with the new exceptions"....Do you have any idea on how to workaround this?

Former Member
0 Kudos

hi vaz

DATA: result TYPE p DECIMALS 3,

number TYPE i VALUE 11.

CATCH SYSTEM-EXCEPTIONS arithmetic_errors = 5.

DO.

number = number - 1.

result = 1 / number.

WRITE: / number, result.

ENDDO.

ENDCATCH.

SKIP.

IF sy-subrc = 5.

WRITE / 'Division by zero!'.

ENDIF.

hope this helps ,

regards,

Vijay

This program calculates the quotient of 1 and NUMBER ten times until the catchable runtime error BCD_ZERODIVIDE occurs. This runtime error belongs to the exception group ARITHMETIC_ERRORS, and is caught in the example using this class.

Message was edited by: Vijay