@@ -282,6 +282,30 @@ calls until a corresponding, enclosing try block is found. It may also associate
282
282
a stack trace that can be used to report uncaught exceptions. However, the
283
283
details of this is left to the embedder.
284
284
285
+ ### Traps and JS API
286
+
287
+ The ` catch ` instruction catches exceptions generated by the ` throw ` instruction,
288
+ but does not catch traps. The rationale for this is that in general traps are
289
+ not locally recoverable and are not needed to be handled in local scopes like
290
+ try-catch.
291
+
292
+ The ` catch ` instruction catches foreign exceptions generated from calls to
293
+ function imports as well, including JavaScript exceptions, with a few
294
+ exceptions:
295
+ 1 . In order to be consistent before and after a trap reaches a JavaScript frame,
296
+ the ` catch ` instruction does not catch exceptions generated from traps.
297
+ 1 . The ` catch ` instruction does not catch JavaScript exceptions generated from
298
+ stack overflow and out of memory.
299
+
300
+ Filtering these exceptions should be based on a predicate that is not observable
301
+ by JavaScript. Traps currently generate instances of
302
+ [ ` WebAssembly.RuntimeError ` ] ( https://webassembly.github.io/reference-types/js-api/#exceptiondef-runtimeerror ) ,
303
+ but this detail is not used to decide type. Implementations are supposed to
304
+ specially mark non-catchable exceptions.
305
+ ([ ` instanceof ` ] ( https://tc39.es/ecma262/#sec-instanceofoperator ) predicate can
306
+ be intercepted in JS, and types of exceptions generated from stack overflow and
307
+ out of memory are implementation-defined.)
308
+
285
309
## Changes to the text format
286
310
287
311
This section describes change in the [ instruction syntax
0 commit comments