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: 

catch exception when interface method is not implemented

0 Kudos

I have some interesting scenarios:

There is already a classic BADI and now a new method is to be added to the interface.

For the implementation class, they, for sure, don't implement the new method, however no syntax errors occur.Yet when runtime error 'CALL_METHOD_NOT_IMPLEMENTED' is raised when the new method is called via a variable of the interface.

CATCH SYSTEM-EXCEPTIONS CALL_METHOD_NOT_IMPLEMENTED = 4.

CALL METHOD g_badi->test.

* do nothing as customer don't necessarily implement the inteface

ENDCATCH.

Even I have try catch statement blocks surrounding the method call, the exception is still raised.

How can I handle it to catch the exception to avoid any short dumps?

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Xin,

Instead of catching SYSTEM-EXCEPTIONS try like below..

DATA : go_exception TYPE REF TO cx_sy_dyn_call_illegal_method, " Exception object
       gv_reason    TYPE string.                               " Reason for Exception


TRY.
 
    CALL METHOD g_badi->test.
 
  CATCH cx_sy_dyn_call_illegal_method INTO go_exception.
    gv_reason = go_exception->if_message~get_text( ).
    " gv_reason has the reason/cause for exception..
ENDTRY.

Cheers,

Jose.

3 REPLIES 3

Former Member
0 Kudos

Hi Xin,

Instead of catching SYSTEM-EXCEPTIONS try like below..

DATA : go_exception TYPE REF TO cx_sy_dyn_call_illegal_method, " Exception object
       gv_reason    TYPE string.                               " Reason for Exception


TRY.
 
    CALL METHOD g_badi->test.
 
  CATCH cx_sy_dyn_call_illegal_method INTO go_exception.
    gv_reason = go_exception->if_message~get_text( ).
    " gv_reason has the reason/cause for exception..
ENDTRY.

Cheers,

Jose.

0 Kudos

HI, Jose

After I use the try catch block, the exception is still thrown out.

Are there any other ways to handle that?

Thanks

Xin

0 Kudos

Hi Xin,

What does this ( 'exception is still thrown out' ) mean? a short-dump??

If yes, search for the raised exception object's type( starts with CX_ ) in the short-dump

and use that instead of cx_sy_dyn_call_illegal_method....

Coding like below is the most generic way and ll catch any class based exception.

TRY.
 
    CALL METHOD g_badi->test. " ur method call
 
  CATCH cx_root.
"Handler code.
ENDTRY.

If u r still getting a short-dump, then probably the exception is being raised somewhere else.......

Cheers,

Jose.