Sign in Join
Wiki copytemporary

WebAssembly/Exceptions: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: WebAssembly/Exceptions

OldNewLine
1+## Historical background
2+
3+Initially WebAssembly did not offer an easy way to implement exceptions. Later, an extension to WebAssembly was proposed, to support exceptions. It was supported by all major browsers. Unfortunately, later this WebAssembly exceptions proposal was deprecated and replaced with another one.
4+
5+## Exception modes
6+
7+To support this whole mess, Free Pascal supports 4 different exception modes.
8+
9+### No exceptions
10+
11+The "No exceptions" mode disables the exception support. Exceptions cannot be handled in this mode, so raising an exception will abort the program. This mode is compatible with all WebAssembly implementations and does not require an extension to support exceptions.
12+
13+This mode is activated with the _-CTnoexceptions_ compiler option.
14+
15+### Branchful exceptions
16+
17+This mode is activated with the _-CTbfexceptions_ compiler option. It doesn't require WebAssembly extensions for exception support, so it also works in all WebAssembly engines. It implements exceptions at a runtime performance cost - branch instructions are added after each function call, to check for raised exceptions. If an exception is detected, the code branches to the nearest enclosing exception handler in the current function, if there is one. Otherwise, the function returns early, so the next caller can handle the exception, simulating the stack unwinding that happens with exceptions. The downside to this mode is that it makes the "happy path" (when no exceptions are raised) slower. The compiler basically adds code to check a flag after every function call.
18+
19+### Legacy exceptions
20+
21+This uses the first extension to WebAssembly to support exceptions:
22+
23+<https://github.com/WebAssembly/exception-handling/blob/master/proposals/exception-handling/legacy/Exceptions.md>
24+
25+It is activated by the _-CTlegacyexceptions_ option. It is supported by the following engines:
26+
27+ * Chrome, since version 95
28+ * Firefox, since version 100
29+ * Safari, since version 15.2
30+
31+### Wasm exceptions
32+
33+This uses the newest WebAssembly exception support extension:
34+
35+<https://github.com/WebAssembly/exception-handling/blob/master/proposals/exception-handling/Exceptions.md>
36+
37+It is activated by the _-CTwasmexceptions_ compiler option. It is supported by the following engines:
38+
39+ * Chrome, since version 137
40+ * Firefox, since version 131
41+ * Safari, since version 18.4
42+ * Wasmtime - experimental support since version 37.0.0. Requires the _-Wexceptions=y_ option to enable.
43+
44+---
45+*From the Free Pascal wiki, page "WebAssembly/Exceptions", as the Internet Archive kept it on 2026-09-26, last changed on 2025-10-06. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history