On Thu, 13 Mar 2003 11:51:35 -0500 Derek Wyatt <[EMAIL PROTECTED]> wrote:
> that makes it this way. There are two ways around this: > > 1) use exceptions. You just have be careful. Make sure that what > 2) Build constructors that are exception free and use an init() method You forgot 3) write the constructor(and other methods) so that it never fails This is the way iostreams do it (they were invented before exceptions became part of C++). They maintain a state internally and allow it to be queried from the outside. Methods are protected with if (i am in a bad state) return; so that it's save to call methods even on a broken object. If you're worried about the overhead of the if (hahaha) you could avoid this and you'll just have to make sure that you check the state whenever something can fail (e.g. after construction). The if-method however is preferable, not only because it prevents errors, but also because it makes the code cleaner. You can just write your code as if everything always succeeds and just put the error checking where it is convenient after a longer stretch of code. This keeps the code clear of lots of error checking. MSB -- Bad comments reveal the bad programmer.
