Skip to content

Commit 0b840da

Browse files
authored
Wrap explainer text to 80 columns (WebAssembly#311)
1 parent 901a9b0 commit 0b840da

File tree

1 file changed

+61
-57
lines changed

1 file changed

+61
-57
lines changed

proposals/exception-handling/Exceptions.md

Lines changed: 61 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ succeeding instructions to process the data.
3636
A WebAssembly exception is created when you throw it with the `throw`
3737
instruction. Thrown exceptions are handled as follows:
3838

39-
1. They can be caught by one of the *catch clauses* in an enclosing try
40-
block of a function body.
39+
1. They can be caught by one of the *catch clauses* in an enclosing try block of
40+
a function body.
4141

4242
1. Throws not caught within a function body continue up the call stack, popping
4343
call frames, until an enclosing try block is found.
@@ -86,21 +86,22 @@ Exception tag indices are used by:
8686
1. The `throw` instruction which creates a WebAssembly exception with the
8787
corresponding exception tag, and then throws it.
8888

89-
2. Catch clauses use a tag to identify the thrown exception it
90-
can catch. If it matches, it pushes the corresponding argument values of the
91-
exception onto the stack.
89+
2. Catch clauses use a tag to identify the thrown exception it can catch. If it
90+
matches, it pushes the corresponding argument values of the exception onto
91+
the stack.
9292

9393
### Exception references
9494

95-
When caught, an exception is reified into an _exception reference_, a value of the new type `exnref`.
96-
Exception references can be used to rethrow the caught exception.
95+
When caught, an exception is reified into an _exception reference_, a value of
96+
the new type `exnref`. Exception references can be used to rethrow the caught
97+
exception.
9798

9899
### Try blocks
99100

100101
A _try block_ defines a list of instructions that may need to process exceptions
101102
and/or clean up state when an exception is thrown. Like other higher-level
102-
constructs, a try block begins with a `try_table` instruction, and ends with an `end`
103-
instruction. That is, a try block is sequence of instructions having the
103+
constructs, a try block begins with a `try_table` instruction, and ends with an
104+
`end` instruction. That is, a try block is sequence of instructions having the
104105
following form:
105106

106107
```
@@ -109,10 +110,11 @@ try_table blocktype catch*
109110
end
110111
```
111112

112-
A try block contains zero or more _catch clauses_. If there are no catch clauses, then the try block does not catch any exceptions.
113+
A try block contains zero or more _catch clauses_. If there are no catch
114+
clauses, then the try block does not catch any exceptions.
113115

114-
The _body_ of the try block is the list of instructions after the last
115-
catch clause, if any.
116+
The _body_ of the try block is the list of instructions after the last catch
117+
clause, if any.
116118

117119
Each `catch` clause can be in one of 4 forms:
118120
```
@@ -121,16 +123,16 @@ catch_ref tag label
121123
catch_all label
122124
catch_all_ref label
123125
```
124-
All forms have a label which is branched to when an exception is cought (see below).
125-
The former two forms have an exception tag associated with it that
126-
identifies what exceptions it will catch.
127-
The latter two forms catch any exception, so that they can be used to define a _default_ handler.
126+
All forms have a label which is branched to when an exception is cought (see
127+
below). The former two forms have an exception tag associated with it that
128+
identifies what exceptions it will catch. The latter two forms catch any
129+
exception, so that they can be used to define a _default_ handler.
128130

129131
Try blocks, like control-flow blocks, have a _block type_. The block type of a
130132
try block defines the values yielded by evaluating the try block when either no
131-
exception is thrown, or the exception is successfully caught by the catch clause.
132-
Because `try_table` defines a control-flow block, it can be
133-
targets for branches (`br` and `br_if`) as well.
133+
exception is thrown, or the exception is successfully caught by the catch
134+
clause. Because `try_table` defines a control-flow block, it can be targets for
135+
branches (`br` and `br_if`) as well.
134136

135137
### Throwing an exception
136138

@@ -160,37 +162,38 @@ Once a catching try block is found for the thrown exception, the operand stack
160162
is popped back to the size the operand stack had when the try block was entered
161163
after possible block parameters were popped.
162164

163-
Then catch clauses are tried in the order
164-
they appear in the catching try block, until one matches. If a matching catch clause is found, control is transferred to the label of that catch clause.
165-
In case of `catch` or `catch_ref`,
166-
the arguments of the exception are pushed back onto the stack.
167-
For `catch_ref` and `catch_all_ref`, an exception reference is then pushed to the stack, which represents the caught exception.
165+
Then catch clauses are tried in the order they appear in the catching try block,
166+
until one matches. If a matching catch clause is found, control is transferred
167+
to the label of that catch clause. In case of `catch` or `catch_ref`, the
168+
arguments of the exception are pushed back onto the stack. For `catch_ref` and
169+
`catch_all_ref`, an exception reference is then pushed to the stack, which
170+
represents the caught exception.
168171

169172
If no catch clauses were matched, the exception is implicitly rethrown.
170173

171-
Note that a caught exception can be rethrown explicitly using the `exnref` and the `throw_ref` instruction.
174+
Note that a caught exception can be rethrown explicitly using the `exnref` and
175+
the `throw_ref` instruction.
172176

173177
### Rethrowing an exception
174178

175-
The `throw_ref` takes an operand of type `exnref` and re-throws the corresponding caught exception.
176-
If the operand is null, a trap occurs.
179+
The `throw_ref` takes an operand of type `exnref` and re-throws the
180+
corresponding caught exception. If the operand is null, a trap occurs.
177181

178182
### JS API
179183

180184
#### Traps
181185

182-
Catch clauses handle exceptions generated by the `throw`
183-
instruction, but do not catch traps. The rationale for this is that in general
184-
traps are not locally recoverable and are not needed to be handled in local
185-
scopes like try blocks.
186+
Catch clauses handle exceptions generated by the `throw` instruction, but do not
187+
catch traps. The rationale for this is that in general traps are not locally
188+
recoverable and are not needed to be handled in local scopes like try blocks.
186189

187190
The `try_table` instruction catches foreign exceptions generated from calls to
188191
function imports as well, including JavaScript exceptions, with a few
189192
exceptions:
190193
1. In order to be consistent before and after a trap reaches a JavaScript frame,
191194
the `try_table` instruction does not catch exceptions generated from traps.
192-
1. The `try_table` instruction does not catch JavaScript exceptions generated from
193-
stack overflow and out of memory.
195+
1. The `try_table` instruction does not catch JavaScript exceptions generated
196+
from stack overflow and out of memory.
194197

195198
Filtering these exceptions should be based on a predicate that is not observable
196199
by JavaScript. Traps currently generate instances of
@@ -232,22 +235,22 @@ check ensures that without access to a WebAssembly module's exported exception
232235
tag, the associated data fields cannot be read.
233236

234237
The `Exception` constructor can take an optional `ExceptionOptions` argument,
235-
which can optionally contain `traceStack` entry. When `traceStack` is
236-
`true`, JavaScript VMs are permitted to attach a stack trace string to
237-
`Exception.stack` field, as in JavaScript's `Error` class. `traceStack`
238-
serves as a request to the WebAssembly engine to attach a stack trace; it
239-
is not necessary to honour if `true`, but `trace` may not be populated if
240-
`traceStack` is `false`. While `Exception` is not a subclass of JavaScript's
241-
`Error` and it can be used to represent normal control flow constructs,
242-
`traceStack` field can be set when we use it to represent errors. The
243-
format of stack trace strings conform to the [WebAssembly stack trace
238+
which can optionally contain `traceStack` entry. When `traceStack` is `true`,
239+
JavaScript VMs are permitted to attach a stack trace string to `Exception.stack`
240+
field, as in JavaScript's `Error` class. `traceStack` serves as a request to the
241+
WebAssembly engine to attach a stack trace; it is not necessary to honour if
242+
`true`, but `trace` may not be populated if `traceStack` is `false`. While
243+
`Exception` is not a subclass of JavaScript's `Error` and it can be used to
244+
represent normal control flow constructs, `traceStack` field can be set when we
245+
use it to represent errors. The format of stack trace strings conform to the
246+
[WebAssembly stack trace
244247
conventions](https://webassembly.github.io/spec/web-api/index.html#conventions).
245248
When `ExceptionOption` is not provided or it does not contain `traceStack`
246249
entry, `traceStack` is considered `false` by default.
247250

248251
To preserve stack trace info when crossing the JS to Wasm boundary, exceptions
249-
can internally contain a stack trace, which is propagated when caught by a `catch[_all]_ref` clause
250-
and rethrown by `throw_ref`.
252+
can internally contain a stack trace, which is propagated when caught by a
253+
`catch[_all]_ref` clause and rethrown by `throw_ref`.
251254

252255
More formally, the added interfaces look like the following:
253256

@@ -331,16 +334,17 @@ document](https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md).
331334

332335
The type `exnref` is represented by the type opcode `-0x17`.
333336

334-
When combined with the [GC proposal](https://github.com/WebAssembly/gc/blob/main/proposals/gc/MVP.md),
335-
there also is a value type `nullexnref` with opcode `-0x0c`.
336-
Furthermore, these opcodes also function as heap type,
337-
i.e., `exn` is a new heap type with opcode `-0x17`,
338-
and `noexn` is a new heap type with opcode `-0x0c`;
339-
`exnref` and `nullexnref` are shorthands for `(ref null exn)` and `(ref null noexn)`, respectively.
337+
When combined with the [GC
338+
proposal](https://github.com/WebAssembly/gc/blob/main/proposals/gc/MVP.md),
339+
there also is a value type `nullexnref` with opcode `-0x0c`. Furthermore, these
340+
opcodes also function as heap type, i.e., `exn` is a new heap type with opcode
341+
`-0x17`, and `noexn` is a new heap type with opcode `-0x0c`; `exnref` and
342+
`nullexnref` are shorthands for `(ref null exn)` and `(ref null noexn)`,
343+
respectively.
340344

341-
The heap type `noexn` is a subtype of `exn`.
342-
They are not in a subtype relation with any other type (except bottom),
343-
such that they form a new disjoint hierarchy of heap types.
345+
The heap type `noexn` is a subtype of `exn`. They are not in a subtype relation
346+
with any other type (except bottom), such that they form a new disjoint
347+
hierarchy of heap types.
344348

345349

346350
##### tag_type
@@ -439,13 +443,13 @@ follows:
439443

440444
###### Tag names
441445

442-
The tag names subsection is a `name_map` which assigns names to a subset of
443-
the tag indices (Used for both imports and module-defined).
446+
The tag names subsection is a `name_map` which assigns names to a subset of the
447+
tag indices (Used for both imports and module-defined).
444448

445449
### Control flow instructions
446450

447-
The control flow instructions are extended to define try blocks and
448-
throws as follows:
451+
The control flow instructions are extended to define try blocks and throws as
452+
follows:
449453

450454
| Name | Opcode | Immediates | Description |
451455
| ---- | ---- | ---- | ---- |

0 commit comments

Comments
 (0)