Skip to Content
avatar image
Former Member

exception handling with fault message type not working

Hi,

I have a sync proxy to proxy scenario and I have created a fault MT and specified in the outbound and Inbound service interface...

*In Inbound proxy I have the following code--*......

.....

RAISE EXCEPTION TYPE z_cx_test_fault

EXPORTING

standard = l_standard_data.

In the sender side abap code which calls the outbound proxy I have the follwing code -

.....

CATCH cx_ai_system_fault INTO lo_cx_ai_system_fault.

txt = lo_cx_ai_system_fault->get_text( ).

WRITE txt.

CATCH z_cx_test_fault INTO lo_cx_test_fault.

txt = lo_cx_standard_message_fault->get_text( ).

WRITE txt.

CATCH cx_ai_application_fault INTO lo_cx_ai_application_fault.

txt = lo_cx_ai_application_fault->get_text( ).

WRITE txt.

when i test the inbound proxy separately I get the custom fault message properly...

however when i run the proxy to proxy sync scenario and the custom exceptionz_cx_test_fault is raised inside the receiver proxy .......control goes to CATCH cx_ai_application_fault and not CATCH z_cx_test_fault .

I understand that cx_ai_application_fault is the super class of all the exception class but why does control go to its exception handling when a custom exception is raised...

Edited by: hema T on Feb 26, 2012 1:16 PM

Edited by: hema T on Feb 26, 2012 1:17 PM

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Feb 27, 2012 at 02:47 PM

    Hi Hema,

    Please check your fault message class name

    You may copied the other object fault class name here.

    You have to assign the faulty class assosiated to your Proxy class.

    RAISE EXCEPTION TYPE z_cx_test_fault

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 27, 2012 at 04:18 PM

    Hi Hema,

    You can always try downcasting the more generic exception to an object of your exception type. Try with the following code:

    CATCH cx_ai_system_fault INTO lo_cx_ai_system_fault.
    lo_cx_test_fault ?= lo_cx_ai_system_fault.
    IF sy-subrc = 0.
       txt = lo_cx_test_fault->get_text( ).
    ELSE.
       txt = lo_cx_ai_system_fault->get_text( ).
    ENDIF.
    WRITE txt.
    

    I have also just spotted an error in your initial code:

    CATCH z_cx_test_fault INTO lo_cx_test_fault.

    txt = lo_cx_standard_message_fault ->get_text( ).

    You use different error object than the one you catch the error into (bolded above).

    Hope this helps,

    Greg

    Add comment
    10|10000 characters needed characters exceeded

    • Hello Hema,

      I have the similar issue of not getting the fault in my custom class. I am still struggling for the resolution.

      However, I do have answer for you since you are now getting the fault in your custom fault class. In you custom fault class 'Attributes' you should notice a table called 'STANDARD'. The actual error message from the proxy is returned in this table. Read this table and you should get the actual error message. GET_TEXT( ) or GET_LONGTEXT( ) will not work here.

      Do let me know how you resolved the custom fault class issue 😊

      Thank you.

      Sud..

  • Feb 26, 2012 at 01:59 PM

    Hi Hema,

    Try changing the sequence of the CATCH blocks, so that the block for your custom z_cx_test_fault exception was before the standard one. I think this might solve your problem. Most probably the sequence does matter when catching the exception, and the reason for your strange behaviour is that SAP only goes into the first CATCH block on the list that matches the type of the error raised (not ALL of the matching CATCH blocks, which is what you expect I think).

    Hope this helps,

    Greg

    Add comment
    10|10000 characters needed characters exceeded