MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / test_getExceptionMessage

Method test_getExceptionMessage

test/test_core.py:1511–1567  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1509
1510 @with_all_eh_sjlj
1511 def test_getExceptionMessage(self):
1512 self.set_setting('ASSERTIONS')
1513 self.maybe_closure()
1514 create_file('main.cpp', '''
1515 #include <emscripten.h>
1516 #include <exception>
1517 #include <stdexcept>
1518 using namespace std;
1519
1520 class myexception : public exception {
1521 virtual const char* what() const throw() { return "My exception happened"; }
1522 } myex;
1523
1524 EMSCRIPTEN_KEEPALIVE extern "C" void throw_exc(int x) {
1525 if (x == 1) {
1526 throw 1000;
1527 }
1528 if (x == 2) {
1529 throw 'c';
1530 }
1531 if (x == 3) {
1532 throw runtime_error("abc");
1533 }
1534 if (x == 4) {
1535 throw myex;
1536 }
1537 if (x == 5) {
1538 throw "abc";
1539 }
1540 }
1541
1542 int main() {
1543 EM_ASM({
1544 for (let i = 1; i < 6; i++){
1545 try {
1546 _throw_exc(i);
1547 } catch(p) {
1548 // Because we are catching and handling the exception in JS, the normal
1549 // exception catching C++ code doesn&#x27;t kick in, so we need to make sure we free
1550 // the exception, if necessary. By decrementing the refcount we trigger the
1551 // free&#x27;ing of the exception.
1552 out(getExceptionMessage(p).toString());
1553 decrementExceptionRefcount(p);
1554 }
1555 }
1556 });
1557 }
1558 ''&#x27;)
1559 expected = ''&#x27;\
1560int,
1561char,
1562std::runtime_error,abc
1563myexception,My exception happened
1564char const*,
1565''&#x27;
1566
1567 self.do_runf('main.cpp', expected)
1568

Callers

nothing calls this directly

Calls 4

maybe_closureMethod · 0.95
create_fileFunction · 0.90
set_settingMethod · 0.80
do_runfMethod · 0.80

Tested by

no test coverage detected