Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2003-09-10 05:47:11


Robert Ramey wrote:
> While studying <boost/throw_exception.hpp> I can't help but wonder
> why it didn't include the following.
>
> namespace boost
> {
>
> #ifdef BOOST_NO_EXCEPTIONS
>
> void throw_exception(std::exception const & e); // user defined
> #define BOOST_TRY
> #define BOOST_CATCH(x) if(0)
>
> #else
>
> template<class E> void throw_exception(E const & e)
> {
> throw e;
> }
> #define BOOST_TRY try
> #define BOOST_CATCH(x) catch
>
> #endif
>
> }
>
> In this case, one could replace try and catch throughout the program
> with BOOST_TRY and BOOST_CATCH and have the program
> automatically build with or without exceptions as appropriate.

Do you have a specific compiler in mind? On MSVC, for instance, try/catch
compile and "work" with exceptions "disabled". You do get an "exceptions
disabled" warning on try, but with if(0) you'd get an "unreachable code"
warning.

It is also worth mentioning that when exceptions are disabled the try/catch
equivalent when wrapping new is to test for 0, not simply ignore the catch
block.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk