Boost logo

Boost :

From: Eugene Karpachov (jk_at_[hidden])
Date: 2001-03-16 06:13:07

Thu, Mar 15, 2001 at 02:38:51AM -0800, Jesse Jones ÐÉÛÅÔ:
> >> 2) CloseHandle can also fail, but you don't want to throw from a dtor so an
> >> assert might be good.
> >
> >Is there any difference? Throwing from destructor has at worst case the same
> >effect as failed assertion; but assert usually disappears from release
> >builds,
> >and throw's not.
> Throwing from a dtor is liable to terminate your app.

Only when you are unwinding stack already - otherwise it just non-desirable
but generally safe.

> Asserting will let you know something is wrong and let the app continue.

Are you talking about some custom "assert"? The standard one terminates the
application when it's condition check failed.

> >> 6) It's better to provide an operator const void*() method instead of
> >> operator bool(). (Unlike bool the const void* one won't implicitly convert
> >> to umpteen different types).
> >
> >For the same reason I'm against implicit conversions when there is no real
> >need for them; why not to provide just member function?
> Many people like writing stuff like "if (p)". And the const void* conversion operator is surprisingly safe.

Well, may be; but if several typings make source more clear, I would prefer to
type them. It's matter of taste.
> >Assert is primarilly debug tool, and library cannot depend from mode it is
> >compiled - debug mode or release mode. It is what std::logic_error (as base
> >class) is for.
> That's one opinion. Another is that there are two more or less distinct classes of errors: system errors like out of memory or writing to a locked file and programmer errors like indexing past the end of an array. Exceptions work well for system errors, but they're often overkill for programmer errors. I *really* don't want every pre/post condition violation and sanity check to throw an exception for every app I write.

So you prefer to just crash all the app?

It is not an _app_ what is written here - it is library. My opinion is that:
even if library user (programmer) violates contract calling library functions,
the library absolutely must not to lay the application down. It is just what
exceptions are for.


Boost list run by bdawes at, gregod at, cpdaniel at, john at