Skip to Content
author's profile photo Former Member
Former Member

Catching abap exception

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?

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Oct 19, 2006 at 10:11 AM

    you can try CATCH statement to catch the exception.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      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?

  • author's profile photo Former Member
    Former Member
    Posted on Oct 19, 2006 at 10:30 AM

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

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 19, 2006 at 12:02 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      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?

  • author's profile photo Former Member
    Former Member
    Posted on Oct 19, 2006 at 05:20 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.