should postconditions be evaluated even if Exception is thrown?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Thu Dec 3 12:06:08 PST 2009


Don wrote:
> Andrei Alexandrescu wrote:
>> Walter Bright wrote:
>>> Brad Roberts wrote:
>>>> Walter Bright wrote:
>>>>> Rory McGuire wrote:
>>>>>> I would think that if a method in a class throws then at least the
>>>>>> class' invariant should be run? does it?
>>>>> No.
>>>>
>>>> Do you consider that broken or correct?
>>>
>>>
>>> Not sure.
>>
>> TDPL says that in non-release mode, public methods have code 
>> instrumented like this:
>>
>> class C {
>>    void m() {
>>       __check_invariant();
>>       scope(exit) __check_invariant();
>>       ... body ...
>>    }
>> }
>>
>> My understanding after a recent discussion to Walter focused on the 
>> topic is that in case a non-Exception Error is thrown, scope(exit) 
>> statements are not guaranteed to be executed, as aren't destructors of 
>> local objects and finally clauses.
>>
>>
>> Andrei
> 
> There are worse problems than that...
> At present, scope(exit) isn't executed if it's preceded by a label (!). 
> And if the scope consists of a single declaration, the compiler will ICE 
> if there is a destructor. Deterministic destruction is still horribly 
> broken.
> 

Ouch. Well, at least these are problems we all agree what the fix should be.

Andrei



More information about the Digitalmars-d mailing list