T
Tom Widmer
And if your "program" is actually a library which other (people's)
programs are going to link to...?
Another viewpoint is that if your program is incapable of continuing -
at least for any other reason than physical limitations (head crash,
CPU explodes, etc.) - then that is programmer error.
Right, and that's what assert helps with, by providing core dumps,
etc. Obviously, an application might want to have its own version of
assert that displays the error to the user before terminating, or
whatever.
As an example, I have written a number of C++ library routines to be
called from the Gauss linear algebra system (think Matlab but
clunkier). If my library code aborts... so does Gauss! My users do not
appreciate this. So I use exceptions to recover elegantly from
(unforseeable) situations such as resource exhaustion, then deliver an
informative explanatory message to the user ("Out of memory. Yes YOU
used it all up. Pig.", etc.).
Yes, that's what exceptions are for - *expected* exceptional
circumstances, not bugs. For example, resource exhaustion, invalid
input from files you don't control, etc. For a robust library
component such as you describe, this may include invalid parameters.
Tom