|
Boost : |
From: Rob Stewart (stewart_at_[hidden])
Date: 2004-05-28 14:36:42
From: "E. Gladyshev" <eegg_at_[hidden]>
> From: "Rob Stewart" <stewart_at_[hidden]>
> > From: "E. Gladyshev" <eegg_at_[hidden]>
> > > From: "Rob Stewart" <stewart_at_[hidden]>
>
> > Why would you want terminate() to be called without stack
> > unwinding on those platforms that do it? What does that get you?
> > I would think that boost::fsm's behavior, being more
> > deterministic, would be preferable.
>
> There could be many reasons, just to list few of them.
> 1. Some platforms pose non-C++ exceptions as normal C++ exception.
> You don't always want those platfrom specific exceptions trigger
> a whole bunch of stuff in your program.
The only platform I know of that does that is Windows/MSVC, and
IIRC, you can handle structured exceptions specially. Perhaps it
means that boost::fsm needs to provide a means to install an
exception handler for those exceptions not already recognized by
the library:
try { throw; }
catch (...) { boost::fsm::detail::handle_exception(); }
void boost::fsm::detail::handle_exception()
{
try { throw; }
catch (type1 const &) { ... };
catch (type2 const &) { ... };
catch (type3 const &) { ... };
catch (...) { user_handler(); }
}
where user_handler is a pointer to function that's initialized to
std::unexpected() and can be overridden by the library user.
It may also be that SEH can be configured to intervene before a
C++ exception is generated by the RTL so those never become C++
exceptions that can muck up the works.
> 2. Your design assumes that all possible exceptions are known
> and you handle them. So any unhandled exception is a bug.
Not quite. What I was showing would rethrow any unknown
exception, leaving to clients to determine how to handle it.
> It is not safe to trigger stack unwinding in a buggy environment.
If you say so. Every application and platform with which I work
is buggy and yet I manage to use exceptions and stack unwinding
works. This is just another case of things not being as pretty
as one might like but that doesn't mean stack unwinding is
faulty.
> These reasons could be of a particular importance in
> control applications where state machines are a must.
>
> But again whether I want it or not, the Standard allows
> implementation where the stack unwinding
> (for unhandled exceptions) never happens.
That doesn't mean that libraries must.
-- Rob Stewart stewart_at_[hidden] Software Engineer http://www.sig.com Susquehanna International Group, LLP using std::disclaimer;
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk