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 ]
Question:
How to construct a nested_exception object with a null exception_ptr in it?
--
Thomas
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
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