What does rethrow_nested throw?

13 views
Skip to first unread message

restor

unread,
May 21, 2009, 7:22:29 PM5/21/09
to
Hi,
N2857 in 18.8.6:4 describes nested_exception::rethrow_nested as
follows:

void rethrow_nested() const; // [[noreturn]]
Throws: the stored exception captured by this nested_exception object.

It is marked as [[noreturn]]. What does it throw if stored exception
is a null exception_ptr object?

Regards,
&rzej

--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std...@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]

Thomas J. Gritzan

unread,
May 22, 2009, 4:10:21 AM5/22/09
to
restor schrieb:

> Hi,
> N2857 in 18.8.6:4 describes nested_exception::rethrow_nested as
> follows:
>
> void rethrow_nested() const; // [[noreturn]]
> Throws: the stored exception captured by this nested_exception object.
>
> It is marked as [[noreturn]]. What does it throw if stored exception
> is a null exception_ptr object?

Question:
How to construct a nested_exception object with a null exception_ptr in it?

--
Thomas

Sean Hunt

unread,
May 22, 2009, 4:06:07 AM5/22/09
to
On May 21, 5:22 pm, restor <akrze...@interia.pl> wrote:
> Hi,
> N2857 in 18.8.6:4 describes nested_exception::rethrow_nested as
> follows:
>
> void rethrow_nested() const; // [[noreturn]]
> Throws: the stored exception captured by this nested_exception object.
>
> It is marked as [[noreturn]]. What does it throw if stored exception
> is a null exception_ptr object?

As I understand it, such a circumstance cannot occur; the
implementation will have called terminate() if you try to construct a
nested_exception when there is no current exception.

Sean Hunt

restor

unread,
May 22, 2009, 2:43:49 PM5/22/09
to
On 22 May, 10:06, Sean Hunt <ride...@gmail.com> wrote:
> On May 21, 5:22 pm, restor <akrze...@interia.pl> wrote:
>
> > Hi,
> > N2857 in 18.8.6:4 describes nested_exception::rethrow_nested as
> > follows:
>
> > void rethrow_nested() const; // [[noreturn]]
> > Throws: the stored exception captured by this nested_exception object.
>
> > It is marked as [[noreturn]]. What does it throw if stored exception
> > is a null exception_ptr object?
>
> As I understand it, such a circumstance cannot occur; the
> implementation will have called terminate() if you try to construct a
> nested_exception when there is no current exception.

this is a piece of code that creates std::nested_exception with null
exception_ptr;

int main() try {
S1: std::nested_exception exc;
S2: exc.rethrow_nested();
}
catch(...) {
}

The default constructor calls std::current_exception, which returns
null pointer if
no exception is currently being handled. The statement at S1 does not
call terminate.
Now, by writing the statement S1, I probably proved that I do not
understand the purpose of nested_exception, because there is no point
in having one with a null, but according to the standard it is
perfectly legal.
We could say that S2 should call terminate if there is nothing to
throw, and the function cannot return (this makes sense), but the
N2857 says no such thing. rethrow_nested is required to throw what it
points to rather than rethrowing currently handled exception, so the
"rethrow; triggers terminate" paragraph (15.1:8) does not apply.

Regards,
&rzej

Reply all
Reply to author
Forward
0 new messages