Skip to content

Support Multiple Catch #216

@BPScott

Description

@BPScott

Support for multiple catch types was added to PHP 7.1 as per https://wiki.php.net/rfc/multiple-catch.
php/php-src#1796 is the PR that merged this feature into php master.

This makes the following code valid in PHP 7.1:

try {
   // Some code...
} catch (ExceptionType1 | ExceptionType2 $e) {
   // Code to handle the exception
}

I'm new to this project (and parsers in general) but from what I can tell the grammar for the try statement should be updated to allow for multiple, pipe-separated qualified-name items.

I think the following grammar is correct:

try-statement:
  'try' compound-statement catch-clauses
  'try' compound-statement finally-clause
  'try' compound-statement catch-clauses finally-clause

catch-clauses:
  catch-clause
  catch-clauses catch-clause

catch-clause:
  'catch' '(' catch-name-list variable-name ')' compound-statement

catch-name-list:
  qualified-name
  catch-name-list '|' qualified-name

finally-clause:
  'finally' compound-statement

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions