Boost logo

Boost :

Subject: Re: [boost] [exception] Incompatibility between boost::throwexception and throw prototype declarations
From: Emil Dotchevski (emil_at_[hidden])
Date: 2008-09-06 03:20:13


On Fri, Sep 5, 2008 at 10:16 PM, vicente.botet <vicente.botet_at_[hidden]> wrote:
> void F() thows (excp) {
> // ...
> G();
> // ...
> }
>
> With 1.136 this code do not compile any more because boost::throw_exception
> throws an unspecified exception. So what can I write instead of
> --unspecified--
>
> void F() thows (excp, --unspecified--) {
> // ...
> G();
> // ...
> }
>
> P.S. I don't push for exception specification in function prototypes, I'm
> just saying that when used the new boost::throw_exception implementation
> brokes the code.

Consider a function declared as:

class my_exception1;
class my_exception2;
void foo() throw(my_exception1,my_exception2);

The above declaration doesn't guarantee that the function does not
throw any other exceptions, only that if it throws something else the
runtime will call std::unexpected(), as if:

try
{
  foo();
}
catch( my_exception1 )
{
  throw;
}
catch( my_exception2 )
{
  throw;
}
catch(...)
{
  std::unexpected();
}

This works regardless whether foo throws via enable_error_info or uses
the throw statement directly. The only observable difference between

throw A();

and

throw enable_error_info(A())

is that in the latter case the exception can be caught not only as A
but also as the unspecified type returned by enable_error_info(A()),
which is why the type is not specified (you can't catch it if you
don't know what it is.)

I suppose you could think of other "differences", like the fact that
enable_error_info lets you throw a type that would be abstract without
the wrapper returned by enable_error_info, etc.

Anyway, what's your point? :)

Emil Dotchevski
Reverge Studios, Inc.
http://www.revergestudios.com/reblog/index.php?n=ReCode


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