    <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/">
     <channel>
        <title>ACCU  :: Hotel Case Study Comments</title>
        <link>https://members.accu.org/index.php/articles/595</link>
        <description>Professionalism in Programming</description>
        <dc:language>en-us</dc:language> 
        <dc:creator>Administrator</dc:creator> 
        <admin:generatorAgent rdf:resource="http://www.xaraya.org" /> 
        <admin:errorReportsTo rdf:resource="mailto:webeditor@accu.org" />
       <sy:updatePeriod>hourly</sy:updatePeriod>
       <sy:updateFrequency>1</sy:updateFrequency>
       <docs>http://backend.userland.com/rss</docs>




<div class="xar-mod-head"><span class="xar-mod-title">Programming Topics + Overload Journal #27 - Aug 1998</span></div>

<table border="0" cellpadding="1" cellspacing="0">
    <tbody>
    <tr>
        <td valign="top">
            Browse in :
       </td>
       <td valign="top">

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c13/">Topics</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c65/">Programming</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c76/">Journals</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c78/">Overload</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c176/">27</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/c65-176/">Any of these categories</a>

                    -                        <a href="https://members.accu.org/index.php/articles/c65+176/">All of these categories</a>
<br />
</td>
   </tr>
   </tbody>
</table>




<div class="xar-error">
   <p>
 <strong>Note:</strong> when you create a new publication type,
the articles module will automatically use the templates
<em>user-display-[publicationtype].xt</em>
and <em>user-summary-[publicationtype].xt</em>.
If those templates do not exist when you try to preview or display a new article,
you'll get this warning :-)  Please place your own templates in themes/<em>yourtheme</em>/modules/articles . The templates will get the extension .xt there. </p>
</div>
<div class="xar-norm xar-standard-box-padding">
   <h1><strong>Title:</strong>&nbsp;Hotel Case Study Comments</h1>
<p><strong>Author:</strong>&nbsp;</p>
<p>
<strong>Date:</strong> 27 August 1999 18:22:42 +01:00 or Fri, 27 August 1999 18:22:42 +01:00</p>
<p><strong>Summary:</strong>&nbsp;</p>
<p><strong>Body:</strong>&nbsp;<div class="section" lang="en">
<div class="titlepage">
<h2><a name="d0e18" id="d0e18"></a></h2>
</div>
<p>Dear Harpist,</p>
<p>First, I share your expierience of being a local expert, and so
I'm not sure about my own ideas. But I put them in anyway and would
like to receive your and other readers' comments.</p>
<p>I currently don't want to say anything about the general design,
as I liked your comments on Paul's code. Some remarks about some
subtle points might follow when I have seen more of your design.
Here, I only want to share some thoughts about exception
declarations. These thoughts relate to your following definition of
class Customer:</p>
<pre class="programlisting">
class Customer
{
  string name;
  string payee;
  Customer(Customer const &amp;);
  Customer &amp; operator=(Customer const &amp;);
public:
  Customer();
  ~Customer() throw();
  string const &amp;getName() const throw();
  string const &amp;getPayee() const throw();
};
</pre>
<p>Is it a good idea to put an empty exception specification to the
read access functions? You write &quot;...reading data should not cause
an exception&quot;. But then you continue &quot;...[this] might not always be
the case&quot;, which is certainly true. With the empty exception
declaration you give garanties about your class which unnecessarily
narrow your possibilities to change your implementation later.
E.g., you might later decide to store your Customer objects on a
database, and your access functions will read directly from that
DB. Then, these functions might well throw an exception. But if you
then change your interface and define &quot;string const &amp; getName()
const throw (DB_lost);&quot; you might break existing code. And if you
leave your empty exception declaration, and catch the possible
exceptions inside getName, you have to handle the exception inside
the class Customer, which might not be the best place to handle
environmental exceptions such as loosing the connection to the DB,
and you prevent your client application, which might well be
prepared to cope with the DB exception, to receive the exception
and handle it. So, I believe its not so good an idea to add any
exception specification to the access functions.</p>
<p>The same reasons which apply to the access functions hold true
for the destructor as well. It might well be that in a future
implementation of your Customer class the destructor has to commit
some DB transactions and so has to throw an exception in case of a
connection failure. I think, the long time proclaimed rule that a
destructor should not throw any exception simply is not true. And
this probably is excactly the reason why the standards committee
added the &quot;uncaught_ exception()&quot; function. So, your destructor
might do anything like this:</p>
<pre class="programlisting">
Customer::~Customer() // no exception specification!
{
  if (uncaught_exception())
  {
    try
    {
      // do everything necessary, but 
      // perhaps performing a rollback 
      // instead of a commit, something  
      // probably went wrong.
    }
    catch(...)
    {
      // this might do nothing, or might 
      // set a global flag or anything 
      // else to signal the ignored 
      // exception to the client app 
      // do not rethrow the exception!
    }
  }
  else
  {
    // normal destructor execution, 
    // which well might throw an 
    // exception
  }
}
</pre>
<p>So, you prevent an exception leaking out of a destructor only in
case of stack unwinding due to another exception, but allow normal
exception handling otherwise.</p>
<p>What's the bottom line? Should you omit exception specifications
completely? Perhaps, this is the easiest way which gives you
maximum flexibility for the future. But this flexibility is not
always required. For me (and this goes much to general design
questions), there are different kinds of C++ classes. You have
general application classes (which typically map directly to
corresponding classes from the analysis), which essentially give
the interface which is used by all your application programs. For
these classes, you need maximum implementation flexibility.</p>
<p>On the other hand, you have basic building blocks, or
components, which you use to implement the general application
classes. E.g. you might have classes like SimpleCustomer (which
just implements the interface of Customer straightforward directly
in memory), DBCustomer (which maps the class to a DB table),
CorbaCustomer (which uses a Customer object anywhere in your
distributed network), etc. These classes state their implementation
in their names and interfaces, and so might well give garanties
about exceptions without locking future implementation changes more
than they are anyway locked by the name.</p>
<p>Of course, there are cases where (empty) exception declarations
are absolutely necessary, e.g. for most member functions of an
exception class itself, but this is not the scope of my remarks
here.</p>
<p>These are my thoughts on exception declarations, but certainly
there are other opinions on this topic, and I would like to see
them.</p>
</div>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
