Is "Out of Memory" a recoverable error?

Walter Bright newshound1 at digitalmars.com
Thu Dec 4 10:28:19 PST 2008


Robert Fraser wrote:
> Robert Jacques wrote:
>> 2) One can still catch an error if need be.
> 
> Not if the function is nothrow, since the function  never sets up an 
> exception handling frame (that's the point of this topic, AFAICT).

Not exactly. If you set up a try-catch, an exception handling frame is 
set up. An exception handling frame is not necessary in order to throw 
an exception, it is only necessary to:

1. catch exceptions
2. unwind exceptions (run destructors)

What happens if a nothrow function does throw is that your destructors 
and finally clauses may not get run in between the throw and the catch. 
For example:

nothrow void foo();

void bar()
{
     try
     {
	foo();
     }
     finally
     {
         will_never_execute(); // even if foo() throws
     }
}

because the compiler will optimize away the finally clause.



More information about the Digitalmars-d mailing list