You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: site/source/docs/porting/Debugging.rst
+39-1Lines changed: 39 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -137,6 +137,45 @@ Debug printouts can even execute arbitrary JavaScript. For example::
137
137
}
138
138
139
139
140
+
Printing exception messages
141
+
===========================
142
+
143
+
Exceptions are thrown from WebAssembly using exception pointers, which means that try/catch/finally blocks in JavaScript will only receive a number, which represents a pointer into linear memory. In order to get the exception message, the user will need to create some WASM code which will extract the meaning from the exception, for example:
It's important to notice that this code will work only for thrown statically allocated exceptions. If your code throws other objects, such as strings or dynamically allocated exceptions, the handling code will need to take that into account. For example, in order to handle thrown strings use:
170
+
171
+
.. code-block:: javascript
172
+
173
+
functiongetExceptionMessage(exception:any): any {
174
+
returntypeof exception ==='number'
175
+
?Module.getExceptionMessage(exception)
176
+
: exception;
177
+
}
178
+
140
179
Disabling optimizations
141
180
=======================
142
181
@@ -285,4 +324,3 @@ Need help?
285
324
The :ref:`Emscripten Test Suite <emscripten-test-suite>` contains good examples of almost all functionality offered by Emscripten. If you have a problem, it is a good idea to search the suite to determine whether test code with similar behavior is able to run.
286
325
287
326
If you've tried the ideas here and you need more help, please :ref:`contact`.
0 commit comments