Boost logo

Boost :

From: Kevin S. Van Horn (Kevin.VanHorn_at_[hidden])
Date: 2002-11-03 00:48:02

David Sankel writes:

> Would an assertion ever be preferable to an exception
> even with debugging?

Have you ever heard of core dumps? On most systems, doing an abort() (as
an assert() or assert-equivalent does) dumps the state of the program to a
core-dump file that you can then examine with your debugger. This lets
you walk up the stack, examining the state of the system at the moment the
error occurred, and often giving a wealth of useful information in
identifying the source of the problem.

Throwing an exception, on the other hand, causes the stack to be unwound,
thus throwing away all of that information. When debugging, throwing an
exception on a logical (programmer) error is the last thing in the world I
want to happen.

Note the distinction between logical errors and "runtime" errors such as
failure of a system call (e.g., you tried to open a file for reading and
it didn't exist) or bad format found for a file (e.g., syntax errors).
Logical errors can be avoided simply (hah!) by writing correct code; they
shouldn't happen at all in production code. Runtime errors, in contrast,
are unavoidable; the user may always specify a nonexistent or corrupted
file, for example, and so you need to handle them in some better manner
than simply crashing the program.

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