Skip to content

Commit 15b92ed

Browse files
committed
Support multiple catch
Fixes #216.
1 parent b5ca441 commit 15b92ed

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

Diff for: spec/11-statements.md

+16-8
Original file line numberDiff line numberDiff line change
@@ -1117,7 +1117,11 @@ catch-clauses:
11171117
catch-clauses catch-clause
11181118
11191119
catch-clause:
1120-
'catch' '(' qualified-name variable-name ')' compound-statement
1120+
'catch' '(' catch-name-list variable-name ')' compound-statement
1121+
1122+
catch-name-list:
1123+
qualified-name
1124+
catch-name-list '|' qualified-name
11211125
11221126
finally-clause:
11231127
'finally' compound-statement
@@ -1134,17 +1138,20 @@ finally-clause:
11341138
<i><a href="#grammar-catch-clauses">catch-clauses</a></i> <i><a href="#grammar-catch-clause">catch-clause</a></i>
11351139

11361140
<i id="grammar-catch-clause">catch-clause:</i>
1137-
catch ( <i><a href="09-lexical-structure.md#grammar-qualified-name">qualified-name</a></i> <i><a href="09-lexical-structure.md#grammar-variable-name">variable-name</a></i> ) <i><a href="#grammar-compound-statement">compound-statement</a></i>
1141+
catch ( <i><a href="#grammar-catch-name-list">catch-name-list</a></i> <i><a href="09-lexical-structure.md#grammar-variable-name">variable-name</a></i> ) <i><a href="#grammar-compound-statement">compound-statement</a></i>
1142+
1143+
<i id="grammar-catch-name-list">catch-name-list:</i>
1144+
<i><a href="09-lexical-structure.md#grammar-qualified-name">qualified-name</a></i>
1145+
<i><a href="#grammar-catch-name-list">catch-name-list</a></i> | <i><a href="09-lexical-structure.md#grammar-qualified-name">qualified-name</a></i>
11381146

11391147
<i id="grammar-finally-clause">finally-clause:</i>
11401148
finally <i><a href="#grammar-compound-statement">compound-statement</a></i>
11411149
</pre>
11421150

11431151
**Constraints**
11441152

1145-
In a *catch-clause*, *parameter-declaration-list* must contain only one
1146-
parameter, and its type must be [`Exception`](17-exception-handling.md#class-exception) or a type derived from
1147-
that class, and that parameter must not be passed byRef.
1153+
Each *qualified-name* inside a *catch-name-list* must name a type derivated from
1154+
[`Exception`](17-exception-handling.md#class-exception).
11481155

11491156
**Semantics**
11501157

@@ -1165,9 +1172,10 @@ try-block that encloses the call to the current function. This process
11651172
continues until a catch-block is found that can handle the current
11661173
exception.
11671174

1168-
The matching is done by considering the class specified by *qualified-name*
1169-
and comparing it to the type of the exception. If the exception is an
1170-
[instance of](10-expressions.md#instanceof-operator) this class then the clause matches.
1175+
The matching is done by considering the classes specified by *qualified-name*
1176+
in *catch-name-list* and comparing it to the type of the exception. If the
1177+
exception is an [instance of](10-expressions.md#instanceof-operator) one of
1178+
the specified classes then the clause matches.
11711179

11721180
If a matching catch-block is located, the Engine prepares to transfer
11731181
control to the first statement of that catch-block. However, before

Diff for: spec/19-grammar.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,11 @@ The grammar notation is described in [Grammars section](09-lexical-structure.md#
870870
<i><a href="#grammar-catch-clauses">catch-clauses</a></i> <i><a href="#grammar-catch-clause">catch-clause</a></i>
871871

872872
<i id="grammar-catch-clause">catch-clause:</i>
873-
catch ( <i><a href="#grammar-qualified-name">qualified-name</a></i> <i><a href="#grammar-variable-name">variable-name</a></i> ) <i><a href="#grammar-compound-statement">compound-statement</a></i>
873+
catch ( <i><a href="#grammar-catch-name-list">catch-name-list</a></i> <i><a href="#grammar-variable-name">variable-name</a></i> ) <i><a href="#grammar-compound-statement">compound-statement</a></i>
874+
875+
<i id="grammar-catch-name-list">catch-name-list:</i>
876+
<i><a href="#grammar-qualified-name">qualified-name</a></i>
877+
<i><a href="#grammar-catch-name-list">catch-name-list</a></i> | <i><a href="#grammar-qualified-name">qualified-name</a></i>
874878

875879
<i id="grammar-finally-clause">finally-clause:</i>
876880
finally <i><a href="#grammar-compound-statement">compound-statement</a></i>

0 commit comments

Comments
 (0)