home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 31,644 of 33,346   
   Dave Abrahams to All   
   Re: Looking for an elegant way to conver   
   08 Nov 11 00:10:29   
   
   From: dave@boostpro.com   
      
   on Mon Nov 07 2011, "Peter C. Chapin"  wrote:   
      
   > There are definitely places where error codes make more sense, to me at   
   > least, than exceptions. For example I find it generally quite awkward to   
   > get an exception when a file fails to open. I usually want to handle   
   > that error locally (or even ignore it) and dealing with exception   
   > machinery in such a context is far less elegant than an old fashion if   
   > statement. In short, failure to open a file just isn't that   
   > exceptional.   
      
   I agree, except in special situations where the application goes out of   
   its way to ensure that it is the only one with access to the file.   
      
   > Also I worry about the strategy of putting catch-all handlers at the top   
   > level of a program. Sure they can prevent the program from aborting and   
   > allow the program to limp along, but is the program still in a good   
   > state after the unexpected error?   
      
   If you code for it, yes.  Normally, catch blocks don't do anything   
   fundamentally different based the type of the exception caught.   
   Information about the exception type only tells you how to extract more   
   information from it, so you can make a better error report.  Not to   
   underplay the importance of a good error report or anything, but it   
   isn't nearly as crucial as maintaining invariants.   
      
   > C++'s RAI idiom is great and really helps control problems in this   
   > area... but can I be confident it has been used consistently   
   > everywhere?   
      
   No more confident than you can be about any other important practice   
   being followed in the code.  But also no less.   
      
   > I'm not anti-exception, but I'm not sold on the idea that they are   
   > inherently superior to error codes in every case.  In fact, I think   
   > there are many cases were error codes are probably better. Judgement   
   > needs to be used when deciding which error reporting strategy to   
   > employ.   
      
   +1.  The efficiency characteristics of EH implementations favor the   
   non-failing case by sometimes as much as 100-to-1, so if the error   
   condition is commonly-occurring and on the program's critical path, you   
   might not want to use exceptions.   
      
   --   
   Dave Abrahams   
   BoostPro Computing   
   http://www.boostpro.com   
      
      
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca