Boost logo

Boost :

From: Alexander Nasonov (alnsn_at_[hidden])
Date: 2006-07-27 14:45:48


Oleg Abrosimov wrote:
>Thank you for your involvement in this topic. I'm very interested in
>pushing it to a complete solution one day.
>
>one further improvement I see is to define simple macros to eliminate
>some details from client code. something like this would be appropriate:
>
>try {
> throw std::logic_error("testing");
>} BOOST_CATCH(my_exception_handler());

I'd changed BOOST_CATCH to something less generic.

>try {
> throw std::logic_error("testing");
>} BOOST_CATCH_EX(exceptions, my_exception_handler());

Well, if it's macro, why not just generate handle-seq (a list of catch clauses) rather then catch(...) { handle(); throw; } ?

For example:

try {
     throw std::logic_error("testing");
} BOOST_CATCH_PP_SEQ((ex1)(ex2)(ex3), my_exception_handler());

You could even pass mpl sequence to a macro if you know a size of the sequence:

try {
     throw std::logic_error("testing");
} BOOST_CATCH_MPL_SEQ(3, mpl::vector<ex1,ex2,ex3>, func);

This could be expanded to

try {
     throw std::logic_error("testing");
}
catch(mpl::at<mpl::vector<ex1,ex2,ex3>,0>::type const& ex)
{
    BOOST_STATIC_ASSERT((
        3 == mpl::size<mpl::vector<ex1,ex2,ex3> >::type::value));
    func(ex);
}
catch(mpl::at<mpl::vector<ex1,ex2,ex3>,1>::type const& ex)
{
    func(ex);
}
catch(mpl::at<mpl::vector<ex1,ex2,ex3>,2>::type const& ex)
{
    func(ex);
}

--
Alexander Nasonov

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