== Quote from Jonathan M Davis (jmdavisp...@gmail.com)'s article > On Sunday 18 July 2010 19:14:11 strtr wrote: > > I'm not sure whether you missed my point or are simple thinking out loud > > about unreachable code being a warning. > > My point was that the unreachable warning was wrong as there is no > > unreachable code. > Except that there _is_. You just can't see it. scope(X) creates a try-catch > block. So, > scope(exit) whatever; > /* code */ > becomes > try > { > */ code */ > } > finally > { > whatever; > } > scope(success) whatever; > /* code */ > becomes > /* code */ > whatever; > scope(failure) whatever; > /* code */ > becomes > try > { > /* code */ > } > catch(Exception e) > { > whatever; > throw e; > } > So, something like > scope(failure) continue; > /* code */ > becomes > try > { > /* code */ > } > catch(Exception e) > { > continue; > throw e; > } > The throw statement is then unreachable. So, the warning is correct. The > problem > is that it's not clear. Ideally, you would have a warning which specifically > mentions the fact that you can't do that sort of thing in a scope statement. > Unless the programmer is thinking about what exactly scope() becomes, the > unreachable statement warning will be confusing. So, that's a problem. It is, > however, correct. It probably merits its own bug report. > - Jonathan M Davis
Thanks for the explanation! But what you are talking about is implementation, nowhere in the spec does it say anything like this (or did I just miss it :). I could find only this about scope(failure): "scope(failure) executes NonEmptyOrScopeBlockStatement when the scope exits due to exception unwinding." So at the very least it is a documentation bug: It should say something about catching the exception and then re-throwing it, or explain that scope guards are sugar for re-throwing try statements