Re: I keep running into long term c++ programmers who refuse to use exceptions
In article
<daniel_t-826A9D.09265808032010@70-3-168-216.pools.spcsdns.net>,
"Daniel T." <daniel_t@earthlink.net> wrote:
Your not quite there IMHO, but you are close. I suggest you read up on
design by contract. Exceptions should be used when contracts are broken.
If it is a contract violation due to a programming error, it should be
an assertion, not an exception. Exceptions can be part of the contract.
Both vector and deque have member-functions called "at()" and these
functions are guaranteed to return the value at a particular index
within the container. In order for the function to be able to meet its
guarantee, it requires that the parameter passed in refers to an element
in the container. Giving a bad parameter is a requirement violation, the
function cannot do its job, so it throws an exception.
The way I see it, an out of range index passed to operator[] is a
contract violation, while an out of range index passed to at() is
perfectly acceptable.
--
Nevin ":-)" Liber <mailto:nevin@eviloverlord.com> 773 961-1620
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]