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 32,384 of 33,346    |
|    DeMarcus to All    |
|    Re: Will we ever be able to throw from a    |
|    07 Jun 12 14:09:56    |
      From: use_my_alias_here@hotmail.com              > 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?       >              I reason like this.              1) This is Defensive Programming* that temporarily may help your project       continue but will be troublesome in the long run when things become       unpredictable and forces you to handle conditions in run-time that       actually are logic errors that should be fixed in compile-time.              2) I would argue that this is the correct way of doing it and rather       check the argument before I provide it to Sqrt(). In essence; don't push       your problem in front of you to other functionality.              Just as a comparison I would guess that most programmers use       std::vector::operator[] that does not throw instead of vector::at() that       throws. People make sure we don't go out of bounds and if we do we want       to know about it quickly and fix it in compile-time.              Regards,       Daniel                     *) http://en.wikipedia.org/wiki/Defensive_programming                     --        [ 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