Boost logo

Boost :

Subject: Re: [boost] [inspect] exceptions (FW: [Boost-users] no exceptions)
From: Joaquin M Lopez Munoz (joaquin_at_[hidden])
Date: 2011-03-23 17:11:43


Vicente BOTET <vicente.botet <at> wanadoo.fr> writes:

>
> > On Tue, Mar 22, 2011 at 12:16 PM, Krzysztof Czainski
> > <1czajnik <at> 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.

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo


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