DIP65: Fixing Exception Handling Syntax

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Wed Jul 9 13:11:45 PDT 2014


On 7/9/2014 1:13 AM, Brian Schott wrote:
> There is no ambiguity in the grammar. "catch (A) { ... }" is not valid. The spec
> requires that you give the exception a name. A spec compliant D compiler MUST
> parse your example code with the LastCatch rule. The fact that DMD does what it
> does is a bug that has been documented for over a year.[1]

Sorry, I misunderstood. The relevant grammar is
https://dlang.org/statement#TryStatement :

  Catches:
     LastCatch
     Catch
     Catch Catches

  LastCatch:
     catch NoScopeNonEmptyStatement

  Catch:
     catch ( CatchParameter ) NoScopeNonEmptyStatement

  CatchParameter:
     BasicType Identifier

What the parser can do is do a lookahead on the ( ) to see if it matches the 
'BasicType Identifier' grammar. Parser::isDeclaration() can be pressed into 
service to do that. This should resolve the issue without breaking code.

BTW, the reason for LastCatch is that it long predates the splitting of 
exceptions into the separate Error and Exception forks.


More information about the Digitalmars-d mailing list