This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++11 status.

1136. Incomplete specification of nested_exception::rethrow_nested()

Section: 17.9.8 [except.nested] Status: C++11 Submitter: Daniel Krügler Opened: 2007-06-06 Last modified: 2016-01-28

Priority: Not Prioritized

View all other issues in [except.nested].

View all issues with C++11 status.

Discussion:

It was recently mentioned in a newsgroup article http://groups.google.de/group/comp.std.c++/msg/f82022aff68edf3d that the specification of the member function rethrow_nested() of the class nested_exception is incomplete, specifically it remains unclear what happens, if member nested_ptr() returns a null value. In 17.9.8 [except.nested] we find only the following paragraph related to that:

void rethrow_nested() const; // [[noreturn]]

-4- Throws: the stored exception captured by this nested_exception object.

This is a problem, because it is possible to create an object of nested_exception with exactly such a state, e.g.

#include <exception>
#include <iostream>

int main() try {
  std::nested_exception e; // OK, calls current_exception() and stores it's null value
  e.rethrow_nested(); // ?
  std::cout << "A" << std::endl;
}
catch(...) {
  std::cout << "B" << std::endl;
}

I suggest to follow the proposal of the reporter, namely to invoke terminate() if nested_ptr() return a null value of exception_ptr instead of relying on the fallback position of undefined behavior. This would be consistent to the behavior of a throw; statement when no exception is being handled.

[ 2009 Santa Cruz: ]

Move to Ready.

Proposed resolution:

Change around 17.9.8 [except.nested] p.4 as indicated:

-4- Throws: the stored exception captured by this nested_exception object, if nested_ptr() != nullptr

- Remarks: If nested_ptr() == nullptr, terminate() shall be called.