
On 7/21/06, Sebastian Redl <sebastian.redl@getdesigned.at> wrote:
The use case for uncaught_exception() is quite simple: it allows destructors to take different actions depending on whether they're destructed due to stack unwind or a different reason. I've used it in a thin wrapper around jpeglib: there you have to wrap the encoding/decoding process in matching function calls, with different end calls depending on whether an error occurred.
I have done a similar thing with uncaught_exception(). I have a wrapper around a series of database primatives, and my destructor looks something like this: database_wrapper::~database_wrapper(void) { if(std::uncaught_exception()) { //Something went wrong, and I cannot be certain that the state of the transaction is valid. rollback_transaction(); } else { //My wrapper is being destroyed on account of leaving scope, so the transaction is good. commit_transaction(); } } This type of activity is very common in any object involved in the oddly name Resource Acquisition is Initialization (RAII) idiom. Jeremy