<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Exception handling for event handler method in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/exception-handling-for-event-handler-method/m-p/12096200#M1972376</link>
    <description>&lt;P&gt;Probably you inherited your exception class from CX_STATIC_CHECK or CX_DYNAMIC_CHECK, it is then wrapped into an exception of class CX_SY_NO_HANDLER, because [CLASS-]EVENTS &amp;lt;event&amp;gt; cannot declare RAISING &amp;lt;exception-classes&amp;gt;.&lt;/P&gt;&lt;P&gt;It's explained in the &lt;A href="https://help.sap.com/doc/abapdocu_753_index_htm/7.53/en-US/index.htm?file=abenexceptions_events.htm"&gt;ABAP documentation - Class-Based Exceptions in Event Handlers&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;Only an exception class derived from CX_NO_CHECK is not wrapped.&lt;/P&gt;&lt;P&gt;Below is a test code, which returns the caught exceptions in the following 3 variables:&lt;/P&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/1739992-catch-of-exception-raised-in-event-handler.png" /&gt;&lt;/P&gt;&lt;P&gt;The test code (run it with Ctrl+Shift+F10):&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;REPORT zzsro_test6b.

CLASS lcl_situation DEFINITION.
  PUBLIC SECTION.
    EVENTS something_happened EXPORTING VALUE(exception) TYPE REF TO cx_root.
ENDCLASS.

CLASS lcl_situation IMPLEMENTATION.
ENDCLASS.

CLASS lcl_observer DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS if_something_happened FOR EVENT something_happened OF lcl_situation IMPORTING exception.
ENDCLASS.

CLASS lcl_observer IMPLEMENTATION.
  METHOD if_something_happened.
    RAISE EXCEPTION exception.
  ENDMETHOD.
ENDCLASS.

CLASS lcx_no_check DEFINITION INHERITING FROM cx_no_check.
ENDCLASS.

CLASS lcx_static_check DEFINITION INHERITING FROM cx_static_check.
ENDCLASS.

CLASS lcx_dynamic_check DEFINITION INHERITING FROM cx_dynamic_check.
ENDCLASS.

CLASS lcl_app DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS main.
ENDCLASS.

CLASS lcl_app IMPLEMENTATION.
  METHOD main.
    lcl_observer=&amp;gt;if_something_happened( NEW lcx_no_check( ) ).
  ENDMETHOD.
ENDCLASS.

CLASS ltc_main DEFINITION
      FOR TESTING
      DURATION SHORT
      RISK LEVEL HARMLESS.
  PRIVATE SECTION.
    METHODS test FOR TESTING.
ENDCLASS.

CLASS ltc_main IMPLEMENTATION.
  METHOD test.
    TRY.
        lcl_observer=&amp;gt;if_something_happened( NEW lcx_no_check( ) ).
      CATCH cx_root INTO DATA(lx_for_no_check).
    ENDTRY.
    TRY.
        lcl_observer=&amp;gt;if_something_happened( NEW lcx_static_check( ) ).
      CATCH cx_root INTO DATA(lx_for_static_check).
    ENDTRY.
    TRY.
        lcl_observer=&amp;gt;if_something_happened( NEW lcx_dynamic_check( ) ).
      CATCH cx_root INTO DATA(lx_for_dynamic_check).
    ENDTRY.
    BREAK-POINT. " DEBUGGER HERE
  ENDMETHOD.
ENDCLASS.&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 16 Oct 2019 17:22:32 GMT</pubDate>
    <dc:creator>Sandra_Rossi</dc:creator>
    <dc:date>2019-10-16T17:22:32Z</dc:date>
    <item>
      <title>Exception handling for event handler method</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/exception-handling-for-event-handler-method/m-p/12096197#M1972373</link>
      <description>&lt;P&gt;I have an event handler DELETE_LOCAL_AFTER_COMMIT whose code is as follows:&lt;/P&gt;
  &lt;P&gt;METHOD delete_local_after_commit. "line no. 1&lt;BR /&gt; LOOP AT gt_del_obj_tab INTO DATA(ls_del_obj_tab).&lt;BR /&gt; TRY.&lt;BR /&gt; CALL METHOD cl_ilm_tadir_api=&amp;gt;tadir_for_local_object&lt;BR /&gt; EXPORTING&lt;BR /&gt; iv_object_category = ls_del_obj_tab-object_category&lt;BR /&gt; iv_object_type = ls_del_obj_tab-object_type&lt;BR /&gt; iv_delflag = 'X'.&lt;BR /&gt; CATCH cx_ilm_tadir_api INTO DATA(lx_error).&lt;BR /&gt; RAISE EXCEPTION lx_error. "line no. 10&lt;BR /&gt; ENDTRY.&lt;BR /&gt; ENDLOOP.&lt;BR /&gt; CLEAR gt_del_obj_tab.&lt;BR /&gt; ENDMETHOD.&lt;/P&gt;
  &lt;P&gt;The piece of code calling event handler is as follows:&lt;/P&gt;
  &lt;P&gt;TRY.&lt;BR /&gt; CALL METHOD cl_ilm_tadir_api=&amp;gt;delete_local_after_commit.&lt;BR /&gt; CATCH cx_ilm_tadir_api INTO DATA(lx_error). "line no. 18&lt;/P&gt;
  &lt;P&gt;ENDTRY.&lt;/P&gt;
  &lt;P&gt;However the exception raised in line no. 10 is not caught in line no. 18. What could be going wrong? (Since my method is an event handler, I cannot even add an exception class to it)&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2019 14:07:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/exception-handling-for-event-handler-method/m-p/12096197#M1972373</guid>
      <dc:creator>former_member333493</dc:creator>
      <dc:date>2019-10-16T14:07:54Z</dc:date>
    </item>
    <item>
      <title>Re: Exception handling for event handler method</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/exception-handling-for-event-handler-method/m-p/12096198#M1972374</link>
      <description>&lt;P&gt;I doubt that an event handler can be called with CALL METHOD... An event handler is to be "called" with RAISE EVENT... (indirectly-loose coupling)&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2019 14:50:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/exception-handling-for-event-handler-method/m-p/12096198#M1972374</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2019-10-16T14:50:15Z</dc:date>
    </item>
    <item>
      <title>Re: Exception handling for event handler method</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/exception-handling-for-event-handler-method/m-p/12096199#M1972375</link>
      <description>&lt;P&gt;In the actual scenario, it is a RAISE EVENT which triggers my event handler. But this in my Local Test Classes where I am forcefully trying to call my event handler DELETE_LOCAL_AFTER_COMMIT (without doing a SET HANDLER...)&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2019 15:00:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/exception-handling-for-event-handler-method/m-p/12096199#M1972375</guid>
      <dc:creator>former_member333493</dc:creator>
      <dc:date>2019-10-16T15:00:39Z</dc:date>
    </item>
    <item>
      <title>Re: Exception handling for event handler method</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/exception-handling-for-event-handler-method/m-p/12096200#M1972376</link>
      <description>&lt;P&gt;Probably you inherited your exception class from CX_STATIC_CHECK or CX_DYNAMIC_CHECK, it is then wrapped into an exception of class CX_SY_NO_HANDLER, because [CLASS-]EVENTS &amp;lt;event&amp;gt; cannot declare RAISING &amp;lt;exception-classes&amp;gt;.&lt;/P&gt;&lt;P&gt;It's explained in the &lt;A href="https://help.sap.com/doc/abapdocu_753_index_htm/7.53/en-US/index.htm?file=abenexceptions_events.htm"&gt;ABAP documentation - Class-Based Exceptions in Event Handlers&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;Only an exception class derived from CX_NO_CHECK is not wrapped.&lt;/P&gt;&lt;P&gt;Below is a test code, which returns the caught exceptions in the following 3 variables:&lt;/P&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/1739992-catch-of-exception-raised-in-event-handler.png" /&gt;&lt;/P&gt;&lt;P&gt;The test code (run it with Ctrl+Shift+F10):&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;REPORT zzsro_test6b.

CLASS lcl_situation DEFINITION.
  PUBLIC SECTION.
    EVENTS something_happened EXPORTING VALUE(exception) TYPE REF TO cx_root.
ENDCLASS.

CLASS lcl_situation IMPLEMENTATION.
ENDCLASS.

CLASS lcl_observer DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS if_something_happened FOR EVENT something_happened OF lcl_situation IMPORTING exception.
ENDCLASS.

CLASS lcl_observer IMPLEMENTATION.
  METHOD if_something_happened.
    RAISE EXCEPTION exception.
  ENDMETHOD.
ENDCLASS.

CLASS lcx_no_check DEFINITION INHERITING FROM cx_no_check.
ENDCLASS.

CLASS lcx_static_check DEFINITION INHERITING FROM cx_static_check.
ENDCLASS.

CLASS lcx_dynamic_check DEFINITION INHERITING FROM cx_dynamic_check.
ENDCLASS.

CLASS lcl_app DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS main.
ENDCLASS.

CLASS lcl_app IMPLEMENTATION.
  METHOD main.
    lcl_observer=&amp;gt;if_something_happened( NEW lcx_no_check( ) ).
  ENDMETHOD.
ENDCLASS.

CLASS ltc_main DEFINITION
      FOR TESTING
      DURATION SHORT
      RISK LEVEL HARMLESS.
  PRIVATE SECTION.
    METHODS test FOR TESTING.
ENDCLASS.

CLASS ltc_main IMPLEMENTATION.
  METHOD test.
    TRY.
        lcl_observer=&amp;gt;if_something_happened( NEW lcx_no_check( ) ).
      CATCH cx_root INTO DATA(lx_for_no_check).
    ENDTRY.
    TRY.
        lcl_observer=&amp;gt;if_something_happened( NEW lcx_static_check( ) ).
      CATCH cx_root INTO DATA(lx_for_static_check).
    ENDTRY.
    TRY.
        lcl_observer=&amp;gt;if_something_happened( NEW lcx_dynamic_check( ) ).
      CATCH cx_root INTO DATA(lx_for_dynamic_check).
    ENDTRY.
    BREAK-POINT. " DEBUGGER HERE
  ENDMETHOD.
ENDCLASS.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Oct 2019 17:22:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/exception-handling-for-event-handler-method/m-p/12096200#M1972376</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2019-10-16T17:22:32Z</dc:date>
    </item>
    <item>
      <title>Re: Exception handling for event handler method</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/exception-handling-for-event-handler-method/m-p/12096201#M1972377</link>
      <description>&lt;P&gt;As you said, I was wrong: an event handler can be called with CALL METHOD.&lt;/P&gt;&lt;P&gt;I posted a detailed answer which explains what probably happened in your case.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2019 17:26:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/exception-handling-for-event-handler-method/m-p/12096201#M1972377</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2019-10-16T17:26:03Z</dc:date>
    </item>
    <item>
      <title>Re: Exception handling for event handler method</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/exception-handling-for-event-handler-method/m-p/12096202#M1972378</link>
      <description>&lt;P&gt;So if the exceptions lcx_no_check, lcx_static_check and lcx_dynamic_check were raised with messages from a message class, it would not be possible to extract the corresponding &lt;STRONG&gt;msgid&lt;/STRONG&gt; and &lt;STRONG&gt;msgno &lt;/STRONG&gt;from the variables lx_for_no_check, lx_for_static_check and lx_for_dynamic_check, right?&lt;/P&gt;</description>
      <pubDate>Fri, 18 Oct 2019 05:46:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/exception-handling-for-event-handler-method/m-p/12096202#M1972378</guid>
      <dc:creator>former_member333493</dc:creator>
      <dc:date>2019-10-18T05:46:58Z</dc:date>
    </item>
    <item>
      <title>Re: Exception handling for event handler method</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/exception-handling-for-event-handler-method/m-p/12096203#M1972379</link>
      <description>&lt;P&gt;You ask a new question, completely unrelated to the previous one, and unrelated to my answer.&lt;/P&gt;&lt;P&gt;It's not required that an exception class is to be related to a message class. If you create your exception class with message(s) from a message class, there's no issue to retrieve the corresponding &lt;STRONG&gt;msgid &lt;/STRONG&gt;and &lt;STRONG&gt;msgno&lt;/STRONG&gt;. If you need more information, please ask a new question with more details.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Oct 2019 05:55:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/exception-handling-for-event-handler-method/m-p/12096203#M1972379</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2019-10-18T05:55:06Z</dc:date>
    </item>
  </channel>
</rss>

