Skip to content

Commit a0093ca

Browse files
authored
Clarify rethrow (#2139)
Clarify rethrow (example: `catch { () { rethrow; } }` is now specified to be an error because the `rethrow` does not occur in an on-catch clause _in the same function_).
1 parent 4e274d2 commit a0093ca

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

specification/dartLangSpec.tex

+18-10
Original file line numberDiff line numberDiff line change
@@ -18031,29 +18031,37 @@ \subsection{Rethrow}
1803118031
<rethrowStatement> ::= \RETHROW{} `;'
1803218032
\end{grammar}
1803318033

18034+
\LMHash{}%
18035+
Consider a \RETHROW{} statement $S$.
18036+
% $f$ as defined below is guaranteed to exist: Every statement occurs in
18037+
% a <block> (a statement may be part of another statement $S_2$, but by
18038+
% induction hypothesis $S_2$ occurs in a <block>), and a <block> can only
18039+
% occur as a statement or in a statement (e.g., in a <finallyPart>), and this
18040+
% induction can only end in a <functionBody>.
18041+
Let $f$ be the immediately enclosing function of $S$.
18042+
A compile-time error occurs unless $S$ is located in an \ON-\CATCH{} clause
18043+
whose immediately enclosing function is $f$.
18044+
1803418045
\LMHash{}%
1803518046
Execution of a \code{\RETHROW} statement proceeds as follows:
1803618047

1803718048
\LMHash{}%
1803818049
Let $f$ be the immediately enclosing function,
18039-
and let \code{\ON{} $T$ \CATCH{} ($p_1$, $p_2$)}
18050+
and let \code{\ON\,\,$T$\,\,\CATCH\,\,($p_1$,\,\,$p_2$)}
1804018051
be the immediately enclosing catch clause (\ref{try}).
1804118052

1804218053
\rationale{%
1804318054
A \RETHROW{} statement always appears inside a \CATCH{} clause,
18044-
and any \CATCH{} clause is semantically equivalent to
18045-
some \CATCH{} clause of the form \code{\ON{} $T$ \CATCH{} (p1, p2)}.
18046-
So we can assume that the \RETHROW{} is enclosed in
18055+
and every \CATCH{} clause is treated as some \CATCH{} clause of the form
18056+
\code{\ON\,\,$T$\,\,\CATCH\,\,(p1,\,\,p2)}.
18057+
So we can consider the \RETHROW{} statement to be enclosed in
1804718058
a \CATCH{} clause of that form.%
1804818059
}
1804918060

1805018061
\LMHash{}%
18051-
The \RETHROW{} statement throws (\ref{statementCompletion})
18052-
with $p_1$ as the exception object and $p_2$ as the stack trace.
18053-
18054-
\LMHash{}%
18055-
It is a compile-time error if a \code{\RETHROW} statement is not
18056-
enclosed within an \ON-\CATCH{} clause.
18062+
The \RETHROW{} statement then throws (\ref{statementCompletion})
18063+
with the value of $p_1$ as the exception object,
18064+
and the value of $p_2$ as the stack trace.
1805718065

1805818066

1805918067
\subsection{Try}

0 commit comments

Comments
 (0)