Boost logo

Boost :

From: Eric Niebler (eric_at_[hidden])
Date: 2005-10-10 14:15:59

Rob Stewart wrote:
> From: Jason Hise <chaos_at_[hidden]>
>>exclusively a debug mode check, or make it a check in both modes? It
>>seems that that should either become:
>>assert ( !e );
>>if ( e ) throw "can't happen";
>>Why do you need both types of checks in the same place?
> That way a debug build asserts, which likely gets a core dump,
> and a release build throws an exception. If the exception is a
> type that is never caught in the code except in main(), then
> main() can report the problem and exit. That gives a clean exit
> with a diagnostic in release builds, while giving the opportunity
> for post mortem debugging in debug builds.

No. An assert should not throw, not in release mode, not ever. If an
assert fails, your program is now in an invalid state. Throwing an
exception potentially causes lots of code to execute that is potentially
dangerous. The correct thing to do is dump core immediately. Maybe try
to save user data into into a separate location, taking care not to
overwrite the last-known-good with potentially corrupt data, but that's
it. Assert != exception.

Eric Niebler
Boost Consulting

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