Boost logo

Boost :

Subject: Re: [boost] [inspect] exceptions (FW: [Boost-users] no exceptions)
From: Vicente BOTET (vicente.botet_at_[hidden])
Date: 2011-03-23 20:51:33


> Message du 23/03/11 22:13
> De : "Joaquin M Lopez Munoz"
> A : boost_at_[hidden]
> Copie à :
> Objet : Re: [boost] [inspect] exceptions (FW: [Boost-users] no exceptions)
>
> Vicente BOTET wanadoo.fr> writes:
>
> >
> > > On Tue, Mar 22, 2011 at 12:16 PM, Krzysztof Czainski
> > > <1czajnik gmail.com> wrote:
> > > > What about boost/detail/no_exceptions_support.hpp?
> > [...]
> >
> > I'm wonderyn if the following wouldn't be more natural
> >
> > void foo() {
> > BOOST_TRY {
> > ...
> > } BOOST_CATCH(const std::bad_alloc&) {
> > ...
> > BOOST_RETHROW
> > } BOOST_CATCH(const std::exception& e) {
> > ...
> > } BOOST_CATCH_ALL {
> > ...
> > }
> > }
>
> If you refer to why BOOST_CATCH_END is needed in the original
> formulation, consider the following:
>
> if(so)
> BOOST_TRY{
> foo();
> }
> BOOST_CATCH(const std::exception& e){
> bar();
> BOOST_RETHROW
> }
> else
> baz();
>
> This, using your variation, expands to
>
> if(so)
> if (true){
> foo();
> }
> else if (false){
> bar();
> }
> else
> baz();
>
> which is equivalent to (note the braces)
>
> if(so){
> if (true){
> foo();
> }
> else if (false){
> bar();
> }
> else{
> baz();
> }
> }
>
> which is clearly not the intention.

Yes I see. This is why I added BOOST_CAT_ALL, but the its use can not be forced and as your example shows can have dramatic effects.

Thanks,
Vicente


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