Structure

Instructions

Control Instructions

The set of recognised instructions is extended with the following:

\[\begin{split}\begin{array}{llcl} \def\mathdef208#1{{}}\mathdef208{instruction} & \href{../syntax/instructions.html#syntax-instr}{\mathit{instr}} &::=& \dots \\&&|& \href{../syntax/instructions.html#syntax-instr-control}{\mathsf{try}}~\href{../syntax/instructions.html#syntax-blocktype}{\mathit{blocktype}}~\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast~(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{catch}}~\href{../syntax/modules.html#syntax-tagidx}{\mathit{tagidx}}~\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast)^\ast~(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{catch\_all}}~\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast)^?~\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{end}} \\ &&|& \href{../syntax/instructions.html#syntax-instr-control}{\mathsf{try}}~\href{../syntax/instructions.html#syntax-blocktype}{\mathit{blocktype}}~\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast~\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{delegate}}~\href{../syntax/modules.html#syntax-labelidx}{\mathit{labelidx}} \\ &&|& \href{../syntax/instructions.html#syntax-instr-control}{\mathsf{rethrow}}~\href{../syntax/modules.html#syntax-labelidx}{\mathit{labelidx}} \\ \end{array}\end{split}\]

The instructions \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{try}}\) and \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{rethrow}}\), are concerned with exceptions. The \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{try}}\) instruction installs an exception handler, and may either handle exceptions in the case of \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{catch}}\) and \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{catch\_all}}\), or rethrow them in an outer block in the case of \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{delegate}}\).

The \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{rethrow}}\) instruction is only allowed inside a \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{catch}}\) or \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{catch\_all}}\) clause and allows rethrowing the caught exception by lexically referring to a the corresponding \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{try}}\).

When \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{try}}\)-\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{delegate}}\) handles an exception, it also behaves similar to a forward jump, effectively rethrowing the caught exception right before the matching \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{end}}\).