I need to perform an action, in multiple separate functions, if scope exits with an exception. The trouble is I don't want to litter my code with scope(failure) everywhere. I already create an instance of a struct at each location, with the sole purpose of doing things at the end of scope.
So my code looks like:

function1()
{
RAIIType transactionHandler;
scope(failure) action;
//code
}

function2()
{
RAIIType transactionHandler;
scope(failure) action;
//code
}

function3()
{
RAIIType transactionHandler;
scope(failure) action;
//code
}

etc.

Ideally I would put the statement from scope(failure) in the struct's destructor and delete the scope(failure) statements. I would need something like c++'s std::uncaught_exceptions() to check if an exception is in flight.

Is there something like this in D?

PS I think that we have here a more general problem, because dlang is missing a feature for composition of scope(...) statements.

Reply via email to