Idea: norecover blocks

dsimcha dsimcha at yahoo.com
Sat Jan 17 18:22:13 PST 2009


== Quote from Walter Bright (newshound1 at digitalmars.com)'s article
> Throwing unrecoverable exceptions still allows a function to be marked
> as nothrow.

This misses the point.  The idea is, you have a function A that calls a library
function B.  B throws an exception that is considered recoverable by whoever wrote
B.  However, within A, you want to treat the exception thrown by B as unrecoverable.

void A() nothrow {
    B();
}

void B() {
    if(someCondition) {
        throw new bException("Some Error");
    }
    // Do stuff.
}

You could catch the bException in A, but that would require enough of a
performance hit that any gain from having A be nothrow would likely be lost (at
least in the cases I've tested).  The idea is that you would declare something like:

void A() nothrow {
    norecover {
        B();
    }
}

and all exceptions thrown by code inside the norecover block would be treated as
unrecoverable, even if they would normally be considered recoverable.



More information about the Digitalmars-d mailing list