Boost logo

Boost :

From: Robert Ramey (ramey_at_[hidden])
Date: 2003-09-09 23:29:50


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.

BOOST_TRY
{
        ...
}
BOOST_CATCH(...)
{
}

would be rendered as
try{
        ...
}
catch(...)
{
        ....
}

on systems supporting exceptions and

{
        ...
}
if(0){
        .... // no op
}

on systems that don't support exceptions.

What am I mising here?


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