<?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: Class Based Exceptions - Emperors New Clothes in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/class-based-exceptions-emperors-new-clothes/m-p/6733248#M1457406</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Nice explanation, Clemens&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 06 Mar 2010 10:38:40 GMT</pubDate>
    <dc:creator>Sandra_Rossi</dc:creator>
    <dc:date>2010-03-06T10:38:40Z</dc:date>
    <item>
      <title>Class Based Exceptions - Emperors New Clothes</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/class-based-exceptions-emperors-new-clothes/m-p/6733243#M1457401</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Many people ask about the technical side of using Class Based Exceptions. The best article I have found to answer that is the one by Gerd Kluger and Christoph Wedler from 2002. That gives a brilliant explanation on the HOW.&lt;/P&gt;&lt;P&gt;What I have always found lacking is the WHY.&lt;/P&gt;&lt;P&gt;I have been too scared to ask this "basic" question in case I got one the of the following arguments&lt;/P&gt;&lt;P&gt;I am too scared to ask a question on the SDN forum asking u201Cwhy are they better than u201Cclassicu201D exceptionsu201D.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Because they are better &lt;/P&gt;&lt;P&gt;Because they are new &lt;/P&gt;&lt;P&gt;Because classic exceptions are u201Cobsoleteu201D &lt;/P&gt;&lt;P&gt;Because they are object orientated &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;None of which is a proper answer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If something is clearly ten million times better than something else then it should be possible to come up with examples of WHY without even thinking about it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The new ABAP editor versus the old one is a fine example. If someone asked me I could list down ten examples off the top of my head. No-one in SDN world seems to be able to do that with Class Based Exceptions. They just state how they work and say u201Cand thatu2019s betteru201D.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am looking for a benefit like&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; - you need less code to achieve the same result&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; - it is clearer what is going on&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; - you can catch an error you canu2019t catch usually&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;u2026. With an actual code sample to shove the benefit right into my face.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Rob Burbank on Mar 4, 2010 5:43 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Mar 2010 16:24:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/class-based-exceptions-emperors-new-clothes/m-p/6733243#M1457401</guid>
      <dc:creator>hardyp180</dc:creator>
      <dc:date>2010-03-04T16:24:43Z</dc:date>
    </item>
    <item>
      <title>Re: Class Based Exceptions - Emperors New Clothes</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/class-based-exceptions-emperors-new-clothes/m-p/6733244#M1457402</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm disappointed to not see any question finally &lt;SPAN __jive_emoticon_name="wink"&gt;&lt;/SPAN&gt; (may I dare tell you: you shouldn't mark this post as a question &lt;SPAN __jive_emoticon_name="wink"&gt;&lt;/SPAN&gt;)&lt;/P&gt;&lt;P&gt;Well, this post would be perfect as a blog.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Mar 2010 22:39:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/class-based-exceptions-emperors-new-clothes/m-p/6733244#M1457402</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2010-03-04T22:39:53Z</dc:date>
    </item>
    <item>
      <title>Re: Class Based Exceptions - Emperors New Clothes</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/class-based-exceptions-emperors-new-clothes/m-p/6733245#M1457403</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here are some quotes from the article above with quotes by me. It is not my intention to slag off the authors of the article, which as I said was the best I have ever read on the subject, I just use them as examples of the type of justifications I have often read about using the new exceptions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;u201CIt is often the case however, that instead of handling exceptions, you want to handle only certain ones and pass the rest to the calleru201D. Why? Why wouldnu2019t you want to handle them? An example would be great.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;u201CThere is no way to group similar errors, like there is with runtime errors u2026. You cannot define your own error groupsu201D. Why would you want to? Again, an example might make sense of this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;u201CThere is no additional information accompanying the exceptionu2026..u201D u2013 once again, what could this be used for? They go on to say that class based exceptions solve a problem that was not there before class based exceptions existed, and therefore they are a good thing, a circular argument like the "because they are good" justification mentioned above.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;u201CWithin the CLEANUP clause, the system can, for example, restore an object to a consistent state or release external resourcesu201D. What do they mean by this? I have no idea. Yet again, an example would be good.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The article  manage to ALMOST explain when to use the three types of exceptions u2013 based on CX_STATIC_CHECK, CX_DYNAMIC_CHECK and CX_NO_CHECK. The article clearly explains HOW each works and how the system treats it, and mention if you use the wrong one the world ends, but once again examples are needed over and above division by zero.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In conclusion, I throw a challenge to the world. Give me just one code example which clearly shows me the benefit of using class based exceptions as opposed to the "old" method. if it's that obvious this shouldn;t me a problem. Then I will shut up.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheersy Cheers&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Paul&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited so that it would format correctly - this a continuation of the original post, not my own copmments (Rob)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Mar 2010 22:46:04 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/class-based-exceptions-emperors-new-clothes/m-p/6733245#M1457403</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-03-04T22:46:04Z</dc:date>
    </item>
    <item>
      <title>Re: Class Based Exceptions - Emperors New Clothes</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/class-based-exceptions-emperors-new-clothes/m-p/6733246#M1457404</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is probably my UK reluctance to just say what I mean rather than beating around the bush. I usually live in Australia where people always say what they mean, but I am still English at heart.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The question i implied - but never explicitlly said - is thus.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can anyone in the world give me a concrete example of why class based exceptions are better than "classic" exceptions beyond saying "because they are" ? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;With an example that makes it so obvious that thereafter I will wonder why I even bothered to raise the question.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My guess is nobdy can.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Mar 2010 19:03:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/class-based-exceptions-emperors-new-clothes/m-p/6733246#M1457404</guid>
      <dc:creator>hardyp180</dc:creator>
      <dc:date>2010-03-05T19:03:29Z</dc:date>
    </item>
    <item>
      <title>Re: Class Based Exceptions - Emperors New Clothes</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/class-based-exceptions-emperors-new-clothes/m-p/6733247#M1457405</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;This is a question for me too. One reason is definitely that class-bases exceptions are standard in most object oriented languages that where object oriented right from the beginning, example is JAVA.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There is just one more really big and quite useful difference:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A class-based exception can be caught directly after it is raised. But if no catch for this exception is found, the logic will go up in the call hierarchy until the search for a matching CATCH is successful. That allows you easily to take specific action for specific exception at any desired level of call hierarchy. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This allows you to create different exceptions for a method and the programmer will decide where to take what action for what kind of exception. This is not possible with classic exceptions. You must react to an exception just where it is raised.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;An other advantage (I don't really use) is that you can define your own exception classes. You can use the exception as a container of whatever attributes you like. This is not possible with a classic exception where you can't do more than assign a certain SY-SUBRC to a specific exception when you call the method or function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I prefer over this attributes concept is to place a  messsage .. INTO dummy statement before raising the exception. Then I have the detailed information in the SY-MSGID SY-MSGTY SY-MSGNO SY-MSGV1 ... SY-MSGV4 variables. Any CATCH may evaluate the SY variables and I have the message in the WHERE-USED list. This is extermely helpful for software maintenance and error management.&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;P&gt;&lt;/P&gt;&lt;P&gt;Sorry, no code example given. Just tried to shed light on the concept.&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, 06 Mar 2010 00:55:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/class-based-exceptions-emperors-new-clothes/m-p/6733247#M1457405</guid>
      <dc:creator>Clemenss</dc:creator>
      <dc:date>2010-03-06T00:55:03Z</dc:date>
    </item>
    <item>
      <title>Re: Class Based Exceptions - Emperors New Clothes</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/class-based-exceptions-emperors-new-clothes/m-p/6733248#M1457406</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Nice explanation, Clemens&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 06 Mar 2010 10:38:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/class-based-exceptions-emperors-new-clothes/m-p/6733248#M1457406</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2010-03-06T10:38:40Z</dc:date>
    </item>
    <item>
      <title>Re: Class Based Exceptions - Emperors New Clothes</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/class-based-exceptions-emperors-new-clothes/m-p/6733249#M1457407</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Certainly class based exceptions are better than the Old Exceptions. The major advantage of using the new Class based exceptions is you don't need to cascade the exception to your caller like you need to do it in the Old exceptions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For demo, Create a global class ZCL_CLASS with two methods. &lt;/P&gt;&lt;P&gt;METH_1 Instance Public .. Impl.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
  me-&amp;gt;meth_2( ).
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;METH_2 Instance Private&lt;/P&gt;&lt;P&gt;Exception - CX_SY_ZERODIVIDE&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
  raise exception cx_sy_zerodivide.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In a program, try to catch this exception:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
data: lo_obj type ref to zcl_class.
create object lo_obj.
* New Exception
TRY.
    lo_obj-&amp;gt;meth_1( ).
  CATCH cx_root.
    write: / 'Class based exception'.
ENDTRY.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Check in debugging, what's going on here and how system caught the exception....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now, let's try to mimic the same thing using the old exception. In the same class, create two methods:&lt;/P&gt;&lt;P&gt;meth_3 instance public &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
  me-&amp;gt;meth_4( ).
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Meth_4 instance private exception NO_DATA_FOUND&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
  raise no_Data_found( ).
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Test program:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
* Old Exception
lo_obj-&amp;gt;meth_3( EXCEPTIONS no_data_found = 4 ).
IF sy-subrc = 4.
  WRITE: 'No data Found'.
ENDIF.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Try to activate ... It would lead to syntax as Meth_3 doesn't have the exception NO_DATA_FOUND. So, we need to define the exception in the meth_3 and change the implemenation to&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
  me-&amp;gt;meth4( exception no_data_found = 4 ).
  if sy-subrc = 4.
    raise no_data_found.
  endif.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now the test program would compile and activate. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, think of the application where you are calling tens of methods which raises these old exceptions in the single method, you need to declare all of the exceptions in the main method (i.e. meth_3). On the other side, if you have used the Class Based exception, you don't need to change the main method. And this is the reason, we are able to catch the catchable exceptions like, CX_SY_ARITHMETIC_OVERFLOW, CX_SY_DYN_CALL_ERROR etc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;From release 700 EhP2, the power of class based exception has been improved by introduction of the RESUME and REPEAT TRY block. &lt;A href="http://help.sap.com/abapdocu_70/en/ABENNEWS-71-EXCEPTIONS.htm" target="test_blank"&gt;http://help.sap.com/abapdocu_70/en/ABENNEWS-71-EXCEPTIONS.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would suggest reading the program flow in case of Old Exception and the new exception: &lt;A href="http://help.sap.com/abapdocu_70/en/abenabap_Exceptions.htm" target="test_blank"&gt;http://help.sap.com/abapdocu_70/en/abenabap_Exceptions.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Naimesh Patel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 06 Mar 2010 18:25:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/class-based-exceptions-emperors-new-clothes/m-p/6733249#M1457407</guid>
      <dc:creator>naimesh_patel</dc:creator>
      <dc:date>2010-03-06T18:25:51Z</dc:date>
    </item>
    <item>
      <title>Re: Class Based Exceptions - Emperors New Clothes</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/class-based-exceptions-emperors-new-clothes/m-p/6733250#M1457408</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Check this one:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1) Define a checked exception, i.e. in your top include&lt;/P&gt;&lt;P&gt;   &lt;/P&gt;&lt;P&gt;  CLASS lcx_dummy_check INHERITING FROM cx_static_check DEFINITION.&lt;/P&gt;&lt;P&gt;  ENDCLASS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2) Define a routine using this exception&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; FORM dummy_check USING ps_data RAISING lcx_dummy_check.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Check ps_data here, raise exception in case of error using&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;   RAISE EXCEPTION TYPE lcx_dummy_check.&lt;/P&gt;&lt;P&gt; ENDFORM.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3) Use the routine anywhere in your code, as often as you want.&lt;/P&gt;&lt;P&gt;   PERFORM dummy_check.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;4) Benefit: &lt;/P&gt;&lt;P&gt;if you do a syntax check, you will get warnings until all lcx_dummy_check exceptions in your code are handled properly.&lt;/P&gt;&lt;P&gt;Now, how do you achieve that with error code?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;J.N.N&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Jun 2010 15:00:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/class-based-exceptions-emperors-new-clothes/m-p/6733250#M1457408</guid>
      <dc:creator>nomssi</dc:creator>
      <dc:date>2010-06-22T15:00:06Z</dc:date>
    </item>
    <item>
      <title>Re: Class Based Exceptions - Emperors New Clothes</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/class-based-exceptions-emperors-new-clothes/m-p/6733251#M1457409</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think Clemens, Naimesh and Jacques have answered this pretty well, as far as the benefits of the new exceptions go. But I wanted to respond more specifically to some of Paul's questions. (Rob did mean that his post was actually Paul's, right? I wasn't sure.)&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Before I start with the specific questions, I want to introduce three principles I'll refer to repeatedly:&lt;/P&gt;&lt;P&gt;&amp;lt;ol&amp;gt;&amp;lt;li&amp;gt;You need to be able to handle exceptions at the most useful place in your code. This means the place where you can either recover from the exception, if possible, or present an intelligent error message to the user, or dump (if the error really is due to a programming problem).&amp;lt;/li&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;lt;li&amp;gt;When you write a method, you want its functionality to be adequately encapsulated. This means, you don't want callers to have to care about low-level technical details in the method. It needs to do its job, but it needs to notify callers about what could go wrong inside the method, and tell them if this occurs. It also needs to allow them to react in the most appropriate way to what has gone wrong.&amp;lt;/li&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;lt;li&amp;gt;You don't want to gum up your callers' code by making them react to low-level details in your method, or react to events that they know won't occur, provided they use your method in a certain way.&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, while I'm not going to write any code, I'm going to describe a solution that I'll reference for examples. We have a screen to display information about a purchase order. The user enters the PO number in a screen field, and the program calls a database access class, which connects to a database (for the sake of this argument, I'm going to pretend we're not connecting to ABAP's own database, which handles connections and resources automatically -- in this example, we need to take care of those details ourselves), and retrieves the PO information. The user can then change the information and save.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;On to the questions:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;blockquote&amp;gt;&amp;lt;i&amp;gt;u201CIt is often the case however, that instead of handling exceptions, you want to handle only certain ones and pass the rest to the calleru201D. Why? Why wouldnu2019t you want to handle them? An example would be great.&amp;lt;/i&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Because you're not at the best place in your code to deal with those exceptions. In the method that accesses the database, let's say we have two possible error situations: either there is a connection problem to the database, or the data is not found. They generate the exceptions CX_CONNECTION_ERROR and CX_NO_DATA_FOUND. If you encounter CX_CONNECTION_ERROR, you might want to try the request again in ten seconds, in case the problem was temporary; or you might want to try a connection to a failover database. In this instance, you're handling the exception. If there was no data found, you have no idea how your caller might want to deal with this. Perhaps it doesn't even expect the data to be there, and is just checking to make sure. You should then propagate the exception to the caller, so that it can handle it properly. You are not handling this exception, because you don't know how to, but your caller probably does. The principle here is: deal with the exceptions you know how to deal with. If you don't know how to deal with an exception, and you have a reasonable belief that the caller does, let it do so.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;blockquote&amp;gt;&amp;lt;i&amp;gt;u201CThere is no way to group similar errors, like there is with runtime errors u2026. You cannot define your own error groupsu201D. Why would you want to? Again, an example might make sense of this.&amp;lt;/i&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let's say there are actually two possible ways in which the connection to the database might fail. Either the system cannot open the underlying connection, or the user has no authorization to connect. These generate the exceptions CX_SOCKET_ERROR and CX_AUTHORIZATION_ERROR, both of which are subclasses of CX_CONNECTION_ERROR. Let's also say that our database connection method decides not to undertake any efforts to retry the connection to the database. It knows that there has been a connection error, but it has insufficient information to tell the user this in a way that is intelligible. (The user wants a message saying that the purchase order could not be retrieved, and why -- not just a message saying that the database connection failed. But the database connection method doesn't know the user scenario in which it is being called.)&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;Therefore, it needs to propagate the exception up to its caller so that it can handle it intelligently. The connection method doesn't care whether an underlying connection error or an authorization error occurred, though. It just had to declare that it raises CX_CONNECTION_ERROR. When this propagated error reaches the caller, it can check to see whether it was actually a CX_SOCKET_ERROR or a CX_AUTHORIZATION_ERROR, to display the correct message to the user, notify a network administrator that a socket error has occurred, and so on. The connection method doesn't care why it couldn't connect, so it can deal with the exception generically. But the caller can take different actions depending upon precisely which error occurred.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you're the caller, and you know you can't recover from &amp;lt;i&amp;gt;any&amp;lt;/i&amp;gt; errors in the connection method, you might even choose to catch CX_ROOT and deal with that. The point is that the system allows you to classify and handle errors hierarchically, instead of at an individual level.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;blockquote&amp;gt;&amp;lt;i&amp;gt;u201CThere is no additional information accompanying the exceptionu2026..u201D u2013 once again, what could this be used for?&amp;lt;/i&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let's say the connection method (or some underlying method) encounters an authorization problem when connecting to the database, and needs to raise CX_AUTHORIZATION_ERROR. It's going to let its caller handle this intelligently, but it wants to give the caller as much information as possible to respond appropriately. It might put more information about the missing authorization into an attribute of CX_AUTHORIZATION_ERROR, so that the system could tell the user precisely which authorization was missing.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Or, for a more business-oriented example, if we have another system for bulk processing of purchase orders, and something goes wrong in a low-level method, the method might want to inform its callers about which purchase order produced an error, so that the method could send a notification to the person responsible for that particular order. The purchase order number might then be stored in an attribute of the exception that is raised, to be dealt with at the correct place in the call chain.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;blockquote&amp;gt;&amp;lt;i&amp;gt;u201CWithin the CLEANUP clause, the system can, for example, restore an object to a consistent state or release external resourcesu201D. What do they mean by this? I have no idea. Yet again, an example would be good.&amp;lt;/i&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CLEANUP seems to be an approximation of Java's &amp;lt;i&amp;gt;finally&amp;lt;/i&amp;gt; block. In Java, it's almost always used for closing communication channels and database connections if an error occurs. Let's say something goes wrong in the method to write PO information to the database. If the write had succeeded, we would have committed our changes to the database. If the write fails, we want to rollback our changes. But either way, we want to &amp;lt;i&amp;gt;close&amp;lt;/i&amp;gt; the connection to the database. (Again, I'm writing here on the assumption that resource handling must be performed by the programmer. This is not true of ABAP databases, but is true of other resources in the language.) We'd then put the database close in the CLEANUP statement -- it must be performed even if execution terminates because of an exception to restore a consistent state.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;Of course, there are other ways you could have done this without class-based exceptions: CLEANUP just makes your code a little more expressive.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;blockquote&amp;gt;&amp;lt;i&amp;gt;The article manage to ALMOST explain when to use the three types of exceptions u2013 based on CX_STATIC_CHECK, CX_DYNAMIC_CHECK and CX_NO_CHECK ... but once again examples are needed over and above division by zero.&amp;lt;/i&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This relates to third principle I established at the top. You want to give your callers a clear interface of what could go wrong in your method. Some of these things have a high probability of occurring in normal execution, and can potentially be handled by the caller. You might want to ensure that these are handled properly, and then you'd use CX_STATIC_CHECK. For instance, CX_NO_DATA_FOUND would be a good candidate for static checking, as there's a high probability that the ID the caller is looking for will not be in the database, and that needs to be dealt with. CX_CONNECTION_ERROR might be a good candidate for CX_DYNAMIC_CHECK -- a database connection error should rarely occur, and your caller might not be prepared to handle it. Therefore, it shouldn't be forced to. If you did force it, it would clutter up the code in the caller unnecessarily. To be honest, I don't really get CX_NO_CHECK. The documentation repeatedly mentions resource bottlenecks. A lot of my understanding of this concept comes from comparison with Java, which uses a very similar exception mechanism to this. Java has java.lang.Exception (which is like CX_STATIC_CHECK) and java.lang.RuntimeException (which is like CX_DYNAMIC_CHECK), but nothing really like CX_NO_CHECK. I assume, though, that CX_NO_CHECK is comparable to java.lang.Error, which is never really subclassed by developers, and relates to extremely low-level problems in the Runtime Environment -- like, indeed, OutOfMemoryError. These should never be caught, and I guess that makes then a sensible analogue for CX_NO_CHECK.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;blockquote&amp;gt;&amp;lt;i&amp;gt;Give me just one code example&amp;lt;/i&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you still need a code example, I can construct one. Any code example that really shows the utility of this functionality is bound to be complicated and long, which is why I think the ones that have been provided have only dealt with part of your question.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As a final aside, on the SAP Professional Journal. I know it has "Professional Journal" at the end, but it's not The Lancet, and doesn't have to try to write like it is. A lot of the articles could be written with half the length, half the academic circumlocution, and twice the clarity. And nobody would take them less seriously.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 Jun 2010 14:30:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/class-based-exceptions-emperors-new-clothes/m-p/6733251#M1457409</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-06-23T14:30:06Z</dc:date>
    </item>
  </channel>
</rss>

