scope() statements and return

Shammah Chancellor via Digitalmars-d digitalmars-d at puremagic.com
Sun Oct 5 19:39:36 PDT 2014


On 2014-10-05 11:28:59 +0000, monarch_dodra said:

> On Saturday, 4 October 2014 at 18:42:05 UTC, Shammah Chancellor wrote:
>> Didn't miss anything.  I was responding to Andrei such that he might 
>> think it's not so straightforward to evaluate that code.
>> I am with you on this.  It was my original complaint months ago that 
>> resulted in this being disallowed behavior.  Specifically because you 
>> could stop error propigation by accident even though you did not intend 
>> to prevent their propigation.  e.g:
>> 
>> int main()
>> {
>> 	scope(exit) return 0;
>> 	assert(false, "whoops!");
>> }
>> 
>> -S
> 
> Isn't this the "should scope(exit/failure) catch Error" issue though?
> 
> In theory, you should seldom ever catch Errors. I don't understand why 
> "scope(exit)" are catching them.

It doesn't "catch" the error. Propigation should continue as normal.  
However, in the case I gave a return statement is executed in a cleanup 
block before propigation can continue.   As has been pointed out, this 
is just like a finally{} block and it behaves the same way.   Throws, 
and returns should be prohibited from those as well.



More information about the Digitalmars-d mailing list