<?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: Handling general errors via class based exceptions in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/handling-general-errors-via-class-based-exceptions/m-p/7578117#M1566097</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You don't need an exception class for each message. Either one class per message class or one per function module to keep some kind of logical division, or you could just lump it all into a big catchall class. You'd still need to create a text per message. Whether it's worthwhile depends on the number of messages I guess. Hmm, so in we're back to I can't see much point to message-based exception classes...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 18 Jan 2011 17:25:44 GMT</pubDate>
    <dc:creator>pokrakam</dc:creator>
    <dc:date>2011-01-18T17:25:44Z</dc:date>
    <item>
      <title>Handling general errors via class based exceptions</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/handling-general-errors-via-class-based-exceptions/m-p/7578110#M1566090</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Fairly standard scenario: I've got this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;  DATA:  l_requester TYPE xubname.

  CALL FUNCTION 'ENQUEUE_EZMYTAB'
    EXPORTING
      username             = i_username
    EXCEPTIONS
      foreign_lock         = 1
      system_failure       = 2
      OTHERS               = 3.

  CASE sy-subrc.
    WHEN 1.
      l_requester = sy-msgv1.
      RAISE EXCEPTION TYPE zcx_my_exception EXPORTING textid   = zcx_my_exception=&amp;gt;lock_error
                                                      user     = i_username
                                                      lockedby = l_requester.
    WHEN 2.
      RAISE EXCEPTION TYPE zcx_my_exception.

  ENDCASE.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But what I really want for &lt;STRONG&gt;WHEN 2&lt;/STRONG&gt; is the class based exception of &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;MESSAGE sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1...&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I.e., in my calling code, I want to catch the exception, and display whatever the original error message was as generated by the ENQUEUE function module.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I suppose I could do this&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA: ls_error TYPE scx_t100key.
...
WHEN 2.
  ls_error-msgid = sy-msgid.
  ls_error-msgty = sy-msgty.
  ls_error-msgno = sy-msgno.
...
  RAISE EXCEPTION TYPE zcx_my_exception EXPORTING textid = ls_error&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; but I can't help feel I'm missing something staggeringly obvious...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;matt&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Jan 2011 16:19:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/handling-general-errors-via-class-based-exceptions/m-p/7578110#M1566090</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2011-01-14T16:19:21Z</dc:date>
    </item>
    <item>
      <title>Re: Handling general errors via class based exceptions</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/handling-general-errors-via-class-based-exceptions/m-p/7578111#M1566091</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;May not be the best of the solution but one way could be to use a string variable (lv_dummy) and then &lt;/P&gt;&lt;P&gt;MESSAGE sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1...INTO lv_dummy.&lt;/P&gt;&lt;P&gt;Now you could pass this string to an attribute in your exception class and use the same syntax &lt;/P&gt;&lt;P&gt; RAISE EXCEPTION TYPE zcx_my_exception EXPORTING textid   = zcx_my_exception=&amp;gt;...&lt;/P&gt;&lt;P&gt;to raise the exception.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Ramneek&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Jan 2011 16:59:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/handling-general-errors-via-class-based-exceptions/m-p/7578111#M1566091</guid>
      <dc:creator>Ramneek</dc:creator>
      <dc:date>2011-01-14T16:59:42Z</dc:date>
    </item>
    <item>
      <title>Re: Handling general errors via class based exceptions</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/handling-general-errors-via-class-based-exceptions/m-p/7578112#M1566092</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Matt,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;this may sound too simple:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For me the real advantage of class-based-exception is that they can be raised in an inner block and caught in an outer block at any level.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I never use the exception attributes to communicate any details, but use&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;IF SY-SUBRC NE 0.
  MESSAGE sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1... INTO lv_string.
  Raise Exception type zcx_my_exception.
ENDIF.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Catching the exception I may (roughly) know where it comes from. As the message variables are present, I can check their values or repeat the MESSAGE without INTO. The main function of MESSAGE INTO is for transparency, the ability to see the whole message in debugger in lv_string and the where-used-list if message is created by programmer..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I really need different reaction for different SY-SUBRC ( = different untyped exception), I'd rather create different class-based exceptions. This helps transparency.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In other oo language you do not have an ABAP message concept with everywhere-present message variables. Why use this crutch of putting the message variable filled by functions exception into exception object attributes only to convert them back to message output?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I prefer [KISS|http://en.wikipedia.org/wiki/KISS_principle].&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Clemens&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 15 Jan 2011 00:09:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/handling-general-errors-via-class-based-exceptions/m-p/7578112#M1566092</guid>
      <dc:creator>Clemenss</dc:creator>
      <dc:date>2011-01-15T00:09:26Z</dc:date>
    </item>
    <item>
      <title>Re: Handling general errors via class based exceptions</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/handling-general-errors-via-class-based-exceptions/m-p/7578113#M1566093</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;All I'm really interested in is returning the message back to the view, in the simplest way, without violating the MVC pattern.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the CATCH, I've currently got: &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;      CATCH zcx_my_exception INTO lx_error.
        MESSAGE lx_Error TYPE 'I'.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'd like to keep that. The trouble with EXPORTING a string to the exception when I raise it, is that I'm limited to 50 characters, as the string goes into MSGV1.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 15 Jan 2011 07:16:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/handling-general-errors-via-class-based-exceptions/m-p/7578113#M1566093</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2011-01-15T07:16:05Z</dc:date>
    </item>
    <item>
      <title>Re: Handling general errors via class based exceptions</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/handling-general-errors-via-class-based-exceptions/m-p/7578114#M1566094</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is what I did in the end:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
    WHEN 1.
      l_requester = sy-msgv1.
      RAISE EXCEPTION TYPE zcx_myexception EXPORTING textid   = zcx_myexception=&amp;gt;lock_error
                                                     user     = me-&amp;gt;username
                                                     lockedby = l_requester.
    WHEN 2.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO l_errmsg.
      RAISE EXCEPTION TYPE zcx_myexception EXPORTING msg = l_errmsg.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In the catch, I do this.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA: lx_error TYPE REF TO zcx_myexception.
...
      CATCH zcx_myexception INTO lx_error.
        IF lx_error-&amp;gt;msg IS INITIAL.
          MESSAGE lx_error TYPE 'I'.
        ELSE.
          MESSAGE lx_error-&amp;gt;msg TYPE 'I'.
        ENDIF.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'd forgotten the obvious point that the attributes of an exception object are directly available!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;matt&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 15 Jan 2011 11:53:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/handling-general-errors-via-class-based-exceptions/m-p/7578114#M1566094</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2011-01-15T11:53:59Z</dc:date>
    </item>
    <item>
      <title>Re: Handling general errors via class based exceptions</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/handling-general-errors-via-class-based-exceptions/m-p/7578115#M1566095</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Matt, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Purely academic as it's after the fact, but isn't this the type of thing that message class based exception classes are supposed to do? I've never really seen the point of raising old-fashioned messages from an exception class , but it seems what you're trying to do. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You'd need to create an exception class for this purpose, but then you should be able to just raise the exception in the usual way and just map the exception attributes to the message variables in the exception class text definition rather than in your code. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers, &lt;/P&gt;&lt;P&gt;Mike&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Jan 2011 16:46:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/handling-general-errors-via-class-based-exceptions/m-p/7578115#M1566095</guid>
      <dc:creator>pokrakam</dc:creator>
      <dc:date>2011-01-18T16:46:44Z</dc:date>
    </item>
    <item>
      <title>Re: Handling general errors via class based exceptions</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/handling-general-errors-via-class-based-exceptions/m-p/7578116#M1566096</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The problem is that these fm are SAP provided. If they threw proper exceptions we won't have a problem. This particular fm only returns two errors - locked, or the locking system is broken. But other fm can return all sorts of error messages. I don't want them to return a message to the screen - as my methods are part of the model (MVC). I don't want to have to write an exception class for every possible scenario the SAP fm might throw up.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Jan 2011 16:52:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/handling-general-errors-via-class-based-exceptions/m-p/7578116#M1566096</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2011-01-18T16:52:38Z</dc:date>
    </item>
    <item>
      <title>Re: Handling general errors via class based exceptions</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/handling-general-errors-via-class-based-exceptions/m-p/7578117#M1566097</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You don't need an exception class for each message. Either one class per message class or one per function module to keep some kind of logical division, or you could just lump it all into a big catchall class. You'd still need to create a text per message. Whether it's worthwhile depends on the number of messages I guess. Hmm, so in we're back to I can't see much point to message-based exception classes...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Jan 2011 17:25:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/handling-general-errors-via-class-based-exceptions/m-p/7578117#M1566097</guid>
      <dc:creator>pokrakam</dc:creator>
      <dc:date>2011-01-18T17:25:44Z</dc:date>
    </item>
    <item>
      <title>Re: Handling general errors via class based exceptions</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/handling-general-errors-via-class-based-exceptions/m-p/7578118#M1566098</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;my cent:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One if not &lt;STRONG&gt;the&lt;/STRONG&gt; main advantage of class-based-exceptions is that they can be caught in &lt;STRONG&gt;any&lt;/STRONG&gt; outer block as long as they are in the blocks interface.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As we can not have more than one exception occur at any given point of time in one LUW, I have no problem with using the SY-MSGxy variables to communicate exception details. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Between RAISING a class-based exception and catching it &lt;STRONG&gt;nothing&lt;/STRONG&gt; is processed except the exception constructor.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I do not think this is a violation of MVC approach, take it as ABAP-specific specialization, very simple and fully transparent.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Clemens&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Jan 2011 18:45:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/handling-general-errors-via-class-based-exceptions/m-p/7578118#M1566098</guid>
      <dc:creator>Clemenss</dc:creator>
      <dc:date>2011-01-18T18:45:13Z</dc:date>
    </item>
  </channel>
</rss>

