Skip to content

Commit f83b400

Browse files
committed
round
1 parent 2671538 commit f83b400

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

site/source/docs/porting/Debugging.rst

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,22 +137,22 @@ Debug printouts can even execute arbitrary JavaScript. For example::
137137
}
138138

139139

140-
Printing C++ exception messages
141-
===============================
140+
Handling C++ exceptions from javascript
141+
=======================================
142142

143143
C++ exceptions are thrown from WebAssembly using exception pointers, which means
144144
that try/catch/finally blocks in JavaScript will only receive a number, which
145145
represents a pointer into linear memory. In order to get the exception message,
146146
the user will need to create some WASM code which will extract the meaning from
147-
the exception. In the example code below we created a function that receives an
148-
``int`` which is pointer to an ``std::exception``, and by casting the pointer
147+
the exception. In the example code below we created a function that receives the
148+
address of a ``std::exception``, and by casting the pointer
149149
returns the ``what`` function call result.
150150

151151
.. code-block:: cpp
152152
153153
#include <bind.h>
154154
155-
std::string getExceptionMessage(int exceptionPtr) {
155+
std::string getExceptionMessage(intptr_t exceptionPtr) {
156156
return std::string(reinterpret_cast<std::exception *>(exceptionPtr)->what());
157157
}
158158
@@ -177,9 +177,9 @@ in order to log the thrown exception.
177177
It's important to notice that this example code will work only for thrown
178178
statically allocated exceptions. If your code throws other objects, such as
179179
strings or dynamically allocated exceptions, the handling code will need to
180-
take that into account. For example, if your code throws either exception
181-
pointers or strings, the javascript code can handle these situations like
182-
this:
180+
take that into account. For example, if your code needs to handle both native
181+
C++ exceptions and JavaScript exceptions you could use the following code to
182+
distinguish between them::
183183

184184
.. code-block:: javascript
185185
@@ -189,6 +189,7 @@ this:
189189
: exception;
190190
}
191191
192+
192193
Disabling optimizations
193194
=======================
194195

0 commit comments

Comments
 (0)