New paper: N3614, unwinding_exception -- Herb Sutter

A new WG21 paper is available. A copy is linked below, and the paper will also appear in the next normal WG21 mailing. If you are not a committee member, please use the comments section below or the std-proposals forum for public discussion.

Document number: N3614

Date: 2013-03-15

unwinding_exception

by Herb Sutter

Excerpt:

This paper does not propose adding language support for D-style scope statements.

Instead, it proposes a new function std::unwinding_exception that returns true iff we are executing a destructor of a stack-based object that is being called to perform stack unwinding.

This enables ScopeGuard and similar uses to automatically and reliably distinguish between success and failure in standard C++ without requiring the user to explicitly signal success or failure by calling a Dismiss function on the guard object.

Add a Comment

Comments are closed.

Comments (2)

0 0

Fernando Pelliccioni said on Mar 15, 2013 04:54 PM:

Hi Herb, I sent an email to std-proposals regarding with this proposal.
0 0

Evgeny Panasyuk said on Mar 30, 2013 05:24 PM:

https://github.com/panaseleus/stack_unwinding
The stack_unwinding is a small header-only C++ library which supplies primitive(class unwinding_indicator) to determining when object destructor is called due to stack-unwinding or due to normal scope leaving.

Currently library is implemented on top of platform-specific implementation of uncaught_exception_count function (it works on MSVC, GCC, Clang, Intel). uncaught_exception_count is a function similar to std::uncaught_exception from standard library, but instead of boolean result it returns unsigned int showing current count of uncaught exceptions.

Here is fully isolated proof-of-concept of scope(failure)/scope(success) implemented based on uncaught_exception_count: http://ideone.com/tyb14x