From: dave@boostpro.com   
      
   on Wed Jun 06 2012, Zeljko Vrba wrote:   
      
   >>> If yes, how do you report inability to fulfill invariants?   
   >>   
   >> You don't. If your invariants are broken your program is broken and   
   >> can't do *anything* reliably, because the whole program has been   
   >>   
   > Let's say I implement a class implementing high-precision floating   
   > point arithmetic and also a square-root function Sqrt which promises   
   > to return a properly rounded result of the same precision as the   
   > input. Now I call Sqrt(-1): what should happen? The function can't   
   > keep its promise since result isn't representable, so should I   
   > 1) throw an exception, or 2) terminate the program?   
      
   The promise is flawed/incomplete. Start by fixing the promise. Either   
   make the promise conditional, (i.e. make non-negativity a precondition),   
   in which case termination would be one appropriate response, or make it   
   more complete (i.e. document that the function throws if the argument is   
   negative), in which case... throw.   
      
   HTH,   
      
   --   
   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)   
|