<?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: Getting call stack / stack trace of caught exception in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/getting-call-stack-stack-trace-of-caught-exception/m-p/772756#M38507</link>
    <description>&lt;P&gt;You have to use the BEFORE UNWIND addition to the CATCH clause:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;REPORT z_catchy_catchy_callstack.

CLASS lcl_foo DEFINITION.
  PUBLIC SECTION.
    METHODS main.
    METHODS method_raising_exception.
ENDCLASS.

CLASS lcl_foo IMPLEMENTATION.

  METHOD main.
    TRY.
        method_raising_exception( ).
      CATCH BEFORE UNWIND cx_root.
        DATA callstack TYPE sys_callst.
        CALL FUNCTION 'SYSTEM_CALLSTACK'
          IMPORTING
            et_callstack = callstack.
        cl_demo_output=&amp;gt;new( )-&amp;gt;write_data( value = callstack )-&amp;gt;display( ).
    ENDTRY.
  ENDMETHOD.

  METHOD method_raising_exception.
    RAISE EXCEPTION TYPE cx_abap_invalid_value.
  ENDMETHOD.

ENDCLASS.

START-OF-SELECTION.
  NEW lcl_foo( )-&amp;gt;main( ).&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 13 Feb 2019 15:30:00 GMT</pubDate>
    <dc:creator>vwegert</dc:creator>
    <dc:date>2019-02-13T15:30:00Z</dc:date>
    <item>
      <title>Getting call stack / stack trace of caught exception</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/getting-call-stack-stack-trace-of-caught-exception/m-p/772749#M38500</link>
      <description>&lt;P&gt;I'd like to get the call stack of an exception which were caught in a try block to identify the location were the exception was thrown. So basically, I want to get the same information which would be visible for a short dump in ST22 under section "Active Calls/Events".&lt;/P&gt;
  &lt;P&gt;In other words, I'm asking for the ABAP equivalent to Throwable.getStackTrace() in Java. &lt;/P&gt;
  &lt;P&gt;I know that there is function module SYSTEM_CALLSTACK, but I tried this within a catch block and just contains the call stack of the current method where the catch block is located, but not the call stack of the exception. &lt;/P&gt;
  &lt;P&gt;Is there any way to get the call stack for an exception in ABAP?&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2019 09:26:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/getting-call-stack-stack-trace-of-caught-exception/m-p/772749#M38500</guid>
      <dc:creator>christian_pfaller</dc:creator>
      <dc:date>2019-02-13T09:26:26Z</dc:date>
    </item>
    <item>
      <title>Re: Getting call stack / stack trace of caught exception</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/getting-call-stack-stack-trace-of-caught-exception/m-p/772750#M38501</link>
      <description>&lt;P&gt;All exceptions have the method GET_SOURCE_POSITION. But it only returns information about the procedure where the exception occurs, not the full stack. Might it be sufficient?&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2019 09:52:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/getting-call-stack-stack-trace-of-caught-exception/m-p/772750#M38501</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2019-02-13T09:52:17Z</dc:date>
    </item>
    <item>
      <title>Re: Getting call stack / stack trace of caught exception</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/getting-call-stack-stack-trace-of-caught-exception/m-p/772751#M38502</link>
      <description>&lt;P&gt;HI Sandra, thanks for your answer, but I'd be indeed be interested in the complete stack. Source position would be a starting point, but when the exception e.g. occurs in standard code, I won't be able to identify the last step in our custom code which would be of more interest to me. &lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2019 10:01:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/getting-call-stack-stack-trace-of-caught-exception/m-p/772751#M38502</guid>
      <dc:creator>christian_pfaller</dc:creator>
      <dc:date>2019-02-13T10:01:17Z</dc:date>
    </item>
    <item>
      <title>Re: Getting call stack / stack trace of caught exception</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/getting-call-stack-stack-trace-of-caught-exception/m-p/772752#M38503</link>
      <description>&lt;P&gt;If you're interested in the custom code only, then you may intercept the exception in the procedure where the standard code is called, and raise a custom exception with PREVIOUS parameter set to the standard exception (you'll have then a chain of exceptions, with the corresponding raised exception locations)&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2019 10:19:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/getting-call-stack-stack-trace-of-caught-exception/m-p/772752#M38503</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2019-02-13T10:19:19Z</dc:date>
    </item>
    <item>
      <title>Re: Getting call stack / stack trace of caught exception</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/getting-call-stack-stack-trace-of-caught-exception/m-p/772753#M38504</link>
      <description>&lt;P&gt;I fully agree - the call to the standard code should be already wrapped in an exception. But I'm exactly interested in debugging possibility (other than ST22) for a situation where this exception chaining is missing. &lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2019 11:25:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/getting-call-stack-stack-trace-of-caught-exception/m-p/772753#M38504</guid>
      <dc:creator>christian_pfaller</dc:creator>
      <dc:date>2019-02-13T11:25:15Z</dc:date>
    </item>
    <item>
      <title>Re: Getting call stack / stack trace of caught exception</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/getting-call-stack-stack-trace-of-caught-exception/m-p/772754#M38505</link>
      <description>&lt;P&gt;If you display the triggering source position (button in the debugger), add a breakpoint there, restart the process (provided it's reproducible, but what can we do with non-reproducible things...) and you'll see the call stack via the debugger. Note that the debugger has also an option to generate the exception object even if it's not requested in the ABAP code.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2019 13:15:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/getting-call-stack-stack-trace-of-caught-exception/m-p/772754#M38505</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2019-02-13T13:15:54Z</dc:date>
    </item>
    <item>
      <title>Re: Getting call stack / stack trace of caught exception</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/getting-call-stack-stack-trace-of-caught-exception/m-p/772755#M38506</link>
      <description>&lt;P&gt;Hi Sandra, invoking the debugger (or any other SAP tool)  does not work for my use case. My intend is to pass the call stack information when executing an RFC function module from outside of the SAP system and I'd like to have these information in the calling external system log. &lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2019 13:43:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/getting-call-stack-stack-trace-of-caught-exception/m-p/772755#M38506</guid>
      <dc:creator>christian_pfaller</dc:creator>
      <dc:date>2019-02-13T13:43:47Z</dc:date>
    </item>
    <item>
      <title>Re: Getting call stack / stack trace of caught exception</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/getting-call-stack-stack-trace-of-caught-exception/m-p/772756#M38507</link>
      <description>&lt;P&gt;You have to use the BEFORE UNWIND addition to the CATCH clause:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;REPORT z_catchy_catchy_callstack.

CLASS lcl_foo DEFINITION.
  PUBLIC SECTION.
    METHODS main.
    METHODS method_raising_exception.
ENDCLASS.

CLASS lcl_foo IMPLEMENTATION.

  METHOD main.
    TRY.
        method_raising_exception( ).
      CATCH BEFORE UNWIND cx_root.
        DATA callstack TYPE sys_callst.
        CALL FUNCTION 'SYSTEM_CALLSTACK'
          IMPORTING
            et_callstack = callstack.
        cl_demo_output=&amp;gt;new( )-&amp;gt;write_data( value = callstack )-&amp;gt;display( ).
    ENDTRY.
  ENDMETHOD.

  METHOD method_raising_exception.
    RAISE EXCEPTION TYPE cx_abap_invalid_value.
  ENDMETHOD.

ENDCLASS.

START-OF-SELECTION.
  NEW lcl_foo( )-&amp;gt;main( ).&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Feb 2019 15:30:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/getting-call-stack-stack-trace-of-caught-exception/m-p/772756#M38507</guid>
      <dc:creator>vwegert</dc:creator>
      <dc:date>2019-02-13T15:30:00Z</dc:date>
    </item>
    <item>
      <title>Re: Getting call stack / stack trace of caught exception</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/getting-call-stack-stack-trace-of-caught-exception/m-p/772757#M38508</link>
      <description>&lt;P&gt;Hello Volker, &lt;/P&gt;&lt;P&gt;many thanks for that hint, that was exactly the information I was looking for! Now I get the call stack as expected. &lt;/P&gt;&lt;P&gt;Regards,&lt;BR /&gt;Christian&lt;/P&gt;</description>
      <pubDate>Thu, 14 Feb 2019 07:56:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/getting-call-stack-stack-trace-of-caught-exception/m-p/772757#M38508</guid>
      <dc:creator>christian_pfaller</dc:creator>
      <dc:date>2019-02-14T07:56:46Z</dc:date>
    </item>
  </channel>
</rss>

