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

Exception Handling

Former Member
0 Likes
671

Hi!

I want to call a function module from my code, surrounded with a try/catch block. The FM calls a selection screen. If I raise an exception inside the "at selection-screen" block for example, I get a dump with uncaught exception, because the internal form of the selection screen hasn't got a raising statement of course.

"exception" is an exception class.

In my program code:


TRY.

      "call selection-screen
      CALL FUNCTION 'MY_FUNCTION_MODULE'

    CATCH exception INTO mr_exception.
      MESSAGE mr_exception TYPE 'I' DISPLAY LIKE 'E'.
ENDTRY.

in the FM

CALL SELECTION-SCREEN 1200.

in the FM at "at selection-screen output"


     RAISE EXCEPTION TYPE exception 

This leads to the dump above.

So anyone got an idea how to catch that exception?

Thanks in advance.

Regards,

Tobi

4 REPLIES 4
Read only

sivasatyaprasad_yerra
Product and Topic Expert
Product and Topic Expert
0 Likes
629

Instead of using try/catch statement, use EXCEPTIONS for the function module and while invoking FM use EXCEPTIONS signature.

Read only

0 Likes
629

well, possible of course, but then I got 2 types of exception handling in my program, which I don't want to.

Isn't there a solution with try/catch?

Read only

0 Likes
629

I'm not sure if anyone is looking for an answer here still, but I'll attempt an answer.

Class Based exceptions cannot be propogated from a section of code that does not have a local memory area. This means Event (START-OF-SELECTION, AT SELECTION-SCREEN, etc) and Dialog Processing. Since the exception cannot be propogated, it hits the system and the system treats it as a dump scenario. In addition, due to the way Class Based Event Handling is processed, an exception cannot be propogated past an event handler.

I am not sure if there is a work around for your problem though. One way may be to use a variable to store the exception that occurred; then when the Function Module itself has control again, check to see if that variable contains a value, it will raise the exception to the application that called the function. Using this and checks against this variable, you would be able to prevent further processing after the exceptions actual occurance.

Global Data Definition



DATA iException TYPE I VALUE 0 .

Function Module



CALL SELECTION-SCREEN 1234

CASE iException .
  WHEN 0 .
   " do nothing, no exception occurred on selection screen.
  WHEN 1 .
     RAISE EXCEPTION CX_Your_Exception_Name .
ENDCASE .


AT SELECTION-SCREEN OUTPUT .
  IF [some condition] .
    iException = 1 . "If your exception occurred.
  ENDIF .

This would allow you to use a global variable to log the exception and report it back to the function module; this will then allow the function module to propogate the correct exception back to the calling procedure.

Read only

0 Likes
629

Hi Steven,

thanks for your answer - didn't know class based exeptions need a local memory area. I will give your workaround a shot.

Regards,

Tobi