DIP65: Fixing Exception Handling Syntax
Timon Gehr via Digitalmars-d
digitalmars-d at puremagic.com
Mon Jul 28 13:51:54 PDT 2014
On 07/28/2014 10:23 PM, Brian Schott wrote:
> On Monday, 28 July 2014 at 20:14:24 UTC, Timon Gehr wrote:
>> foreach(i;0..n){
>> // ...
>> }
>> (&x).foo();
>>
>> try{
>> // ...
>> }catch(Exception e){
>> return e;
>> }
>> (new Exception("hi")).msg.writeln;
>
> I don't see how these are ambiguous.
Both are ambiguous for the same reason. They are ambiguous because there
exist delegate/function literals of the form
enum e={ return 2; }();
^~~~~~~~~~~~~
an expression
The following program demonstrates how to disambiguate the code such
that it is parsed in the alternative way:
import std.stdio;
void bar(){
foreach(x;0..10)(){
// ...
}
(&x).foo();
}
void main(){
Exception e(){
try{
// ...
throw new Exception("foo");
}catch delegate(Exception e){
return e;
}(new Exception("hi")).msg.writeln;
return null;
}
e();
}
More information about the Digitalmars-d
mailing list