|
Boost : |
From: John Maddock (jm_at_[hidden])
Date: 2002-08-10 05:35:31
> How about...
>
>
> namespace boost {
>
> struct exception_throw_policy
> {
> template <class E> void handle_exception(E const & e)
> {
> throw e;
> }
> };
>
> struct exception_assert_policy
> {
> template <class E> void handle_exception(E const & e)
> {
> //...
> }
> };
>
> template <class E> void throw_exception(E const & e)
> {
> typename exception_policy;
> exception_policy::handle_exception(e);
> }
>
> }
>
> #ifndef BOOST_NO_EXCEPTIONS
> namespace boost {
> typedef exception_throw_policy exception_policy;
> }
> #endif
>
> It would be up the user to add someplace:
>
> namespace boost {
> typedef exception_assert_policy exception_policy;
> }
>
> If that's what they want.
Not bad, but the system can't really tell whether exception_policy has been
defined by the user or not. This would seem to be one of those sad cases
where macros actually add more functionality:
#ifndef BOOST_THROW_EXCEPTION
#ifdef BOOST_NO_EXCEPTIONS
#include <cstdio>
#define BOOST_THROW_EXCEPTION(x) std::fprintf(std::stderr, e.what()),
abort()
#else
#define BOOST_THROW_EXCEPTION(x) throw x
#endif
#endif
Regards,
John Maddock
http://ourworld.compuserve.com/homepages/john_maddock/index.htm
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk