Idea: norecover blocks
Walter Bright
newshound1 at digitalmars.com
Sat Jan 17 20:35:28 PST 2009
dsimcha wrote:
> 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.
void A() nothrow {
try
{
B();
}
catch (Object o)
{
abort();
}
}
will do it.
More information about the Digitalmars-d
mailing list