@@ -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
143143C++ exceptions are thrown from WebAssembly using exception pointers, which means
144144that try/catch/finally blocks in JavaScript will only receive a number, which
145145represents a pointer into linear memory. In order to get the exception message,
146146the 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
149149returns 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
178178statically allocated exceptions. If your code throws other objects, such as
179179strings 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
0 commit comments