<?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: Cannot trap exceptions in superclass constructor in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/cannot-trap-exceptions-in-superclass-constructor/m-p/2519386#M570122</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ah... figured it out!&lt;/P&gt;&lt;P&gt;In my tests I started out using cx_bapi_exception in the superclass and several days later in the subclass I used cx_bapi* -&amp;gt; F4 and ended up with cx_bapi_error - not realizing I used a different exception.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since it dumped with &amp;lt;i&amp;gt;unhandled_exception&amp;lt;/i&amp;gt; and I thought it was the same in both constructors, I assumed there was something special about CONSTRUCTORs causing exceptions not to propagate through to the caller.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks all for the input though, it was an interesting discussion and I certainly learned a bit more about in-depth oo &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 17 Jul 2007 10:48:14 GMT</pubDate>
    <dc:creator>pokrakam</dc:creator>
    <dc:date>2007-07-17T10:48:14Z</dc:date>
    <item>
      <title>Cannot trap exceptions in superclass constructor</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/cannot-trap-exceptions-in-superclass-constructor/m-p/2519379#M570115</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, &lt;/P&gt;&lt;P&gt;Scenario: A superclass has a constructor with an exception. In a subclass I also define a constructor. It helpfully generates the following code: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;method CONSTRUCTOR .
**TRY.
*CALL METHOD SUPER-&amp;gt;CONSTRUCTOR
*    .
** CATCH CX_STATIC_CHECK .
**ENDTRY.
endmethod.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;When I uncomment the call method I get a warning that an exception is unhandled. When I uncomment everything, it throws a tantrum, saying &amp;lt;i&amp;gt;"You cannot call the constructor of the superclass conditionally"&amp;lt;/i&amp;gt; and will not compile. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is this supposed to work like this? Can one not trap exceptions? Nothing on OSS either. (Basis version 620)&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>Mon, 16 Jul 2007 15:34:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/cannot-trap-exceptions-in-superclass-constructor/m-p/2519379#M570115</guid>
      <dc:creator>pokrakam</dc:creator>
      <dc:date>2007-07-16T15:34:49Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot trap exceptions in superclass constructor</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/cannot-trap-exceptions-in-superclass-constructor/m-p/2519380#M570116</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Mike&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I believe the message is quite clear: If&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;CALL METHOD super-&amp;gt;constructor.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;fails then it makes absolutely no sense to continue with the CONSTRUCTOR method of any subclass (-&amp;gt; TRY - ENDTRY block). Thus, calling the CONSTRUCTOR method of a superclass is an &amp;lt;i&amp;gt;all-or-nothing&amp;lt;/i&amp;gt; statement which cannot be made conditionally by using the TRY/CATCH block.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;  Uwe&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Jul 2007 16:30:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/cannot-trap-exceptions-in-superclass-constructor/m-p/2519380#M570116</guid>
      <dc:creator>uwe_schieferstein</dc:creator>
      <dc:date>2007-07-16T16:30:40Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot trap exceptions in superclass constructor</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/cannot-trap-exceptions-in-superclass-constructor/m-p/2519381#M570117</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Uwe, &lt;/P&gt;&lt;P&gt;Partly correct: No it doesn't make sense to continue &amp;lt;i&amp;gt;instantiating&amp;lt;/i&amp;gt; if the superclass fails but it does make sense to at least complete a try-endtry block to at least handle the error (ironically, as per the code it generates).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A superclass exception will always end up as an UNCAUGHT_EXCEPTION dump as I cannot do a catch-raise construct to pass the exception back to the instantiator of the subclass. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks, &lt;/P&gt;&lt;P&gt;Mike&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Jul 2007 16:53:27 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/cannot-trap-exceptions-in-superclass-constructor/m-p/2519381#M570117</guid>
      <dc:creator>pokrakam</dc:creator>
      <dc:date>2007-07-16T16:53:27Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot trap exceptions in superclass constructor</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/cannot-trap-exceptions-in-superclass-constructor/m-p/2519382#M570118</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;gt; Is this supposed to work like this? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yep.&lt;/P&gt;&lt;P&gt;This is not exactly an ABAP-Problem, it's an OO issue. There have been actually lots of disscussions about it. In Java for example, constructors have to start with a call to super(). The reason is simple: prevent modifications to instance-attributes of the sub-class before the object could have been initialized. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The problem with your code is that you try to catch the exception within the constuctor. Instead you should delegate it in the subclass-constructor and catch the exception on your "CREATE OBJECT sub." call.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Jul 2007 18:05:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/cannot-trap-exceptions-in-superclass-constructor/m-p/2519382#M570118</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-07-16T18:05:39Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot trap exceptions in superclass constructor</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/cannot-trap-exceptions-in-superclass-constructor/m-p/2519383#M570119</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I agree with Hristo - but I want to take this discussion a step further. I don't think it is correct that any exception should be thrown from a constructor. That is not - in a "purist" view - what a constructor is for. Remember the main pupose of a constructor is to initialize instance variables. I know we all break this rule from time to time, but that is why the compiler is "surprised" to find a try - endtry around a contructor call.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Jul 2007 07:31:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/cannot-trap-exceptions-in-superclass-constructor/m-p/2519383#M570119</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-07-17T07:31:12Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot trap exceptions in superclass constructor</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/cannot-trap-exceptions-in-superclass-constructor/m-p/2519384#M570120</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for your inputs. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;@Hristo: I don't get what you mean by "delegate it in the subclass-constructor and catch the exception on your "CREATE OBJECT sub." call."? I thought this is exactly what I'm trying to accomplish...? If the superclass constructor fails I want to catch the exception in the code that is trying to instantiate the subclass. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;@Alistair: Interesting comment but I would disagree. This may or may not be be correct in a pure non-SAP OO context, but my context is a Business Class in a SAP environment. It is an object with a key, and the constructor's job is also to validate that I'm not trying to instantiate nonsense. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A simple example would be an order class with a subclass for a specific order type. The superclass constructor validates that the order number we're instantiating exists and the subclass validates that the order type is valid for the subclass. I cannot use parameters since I should not instantiate the object with invalid input data. Thus an exception is the only way to communicate a failure back to the instantiator. Or have I missed another ABAP OO concept that I'm supposed to be using here? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If nothing else then the generated code for a new constructor is misleading.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Jul 2007 08:28:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/cannot-trap-exceptions-in-superclass-constructor/m-p/2519384#M570120</guid>
      <dc:creator>pokrakam</dc:creator>
      <dc:date>2007-07-17T08:28:20Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot trap exceptions in superclass constructor</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/cannot-trap-exceptions-in-superclass-constructor/m-p/2519385#M570121</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Good Point Mike - the pure OO environment and the "real" SAP OO environment are sometimes very different &lt;SPAN __jive_emoticon_name="wink"&gt;&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think what Hristo is saying is put your CREATE OBJECT in a TRY...ENDTRY block rather than catching the exception in the constructor.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope that helps,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Alistair&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Jul 2007 09:55:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/cannot-trap-exceptions-in-superclass-constructor/m-p/2519385#M570121</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-07-17T09:55:19Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot trap exceptions in superclass constructor</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/cannot-trap-exceptions-in-superclass-constructor/m-p/2519386#M570122</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ah... figured it out!&lt;/P&gt;&lt;P&gt;In my tests I started out using cx_bapi_exception in the superclass and several days later in the subclass I used cx_bapi* -&amp;gt; F4 and ended up with cx_bapi_error - not realizing I used a different exception.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since it dumped with &amp;lt;i&amp;gt;unhandled_exception&amp;lt;/i&amp;gt; and I thought it was the same in both constructors, I assumed there was something special about CONSTRUCTORs causing exceptions not to propagate through to the caller.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks all for the input though, it was an interesting discussion and I certainly learned a bit more about in-depth oo &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Jul 2007 10:48:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/cannot-trap-exceptions-in-superclass-constructor/m-p/2519386#M570122</guid>
      <dc:creator>pokrakam</dc:creator>
      <dc:date>2007-07-17T10:48:14Z</dc:date>
    </item>
  </channel>
</rss>

