|
Boost : |
From: Ross Smith (r-smith_at_[hidden])
Date: 2002-10-12 02:05:35
On Saturday, 12 October 2002 18:28, Joel de Guzman wrote:
>
> From: "Carl Daniel" <cpdaniel_at_[hidden]>
>
> > Exception classes thrown by Spirit (parser_error<>,
> > illegal_backtracking) don't derive from std::exception - shouldn't
> > they?
>
> I'm not sure. Should it? What will be the benefits in doing so?
> The truth is, I'm not quite happy with the standard C++ exceptions.
> For one, it's hard coded the what() to be a string.
The big advantage of requiring all exceptions to be derived from
std::exception, as I see it, is that you can write your main function
like this...
int main() {
try {
// code goes here
return 0;
}
catch (const std::exception& ex) {
std::cerr << "*** " << ex.what() << "\n";
return EXIT_FAILURE;
}
}
...and be confident of getting an error message instead of a crash if
anything gets thrown that you haven't explicitly caught. You can do the
same thing in other functions that you don't want anything to escape
from (e.g. destructors, extern "C" functions that will be used as
callbacks, etc). If you can't rely on everything having std::exception
in its family tree, you have to either use catch (...), which denies
you the chance of logging any meaningful error message, or write a
whole stack of catch clauses for every exception you can think of.
I'd like to suggest (to the Boost readership in general) that this
should be made a requirement for all Boost libraries.
-- Ross Smith ......... r-smith_at_[hidden] ......... Auckland, New Zealand "I'm deeply concerned about a leader who has ignored the United Nations for all these years, refused to conform to resolution after resolution after resolution, who has weapons of mass destruction." -- George W. Bush, Jr.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk