(self)
| 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'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'ing of the exception. |
| 1552 | out(getExceptionMessage(p).toString()); |
| 1553 | decrementExceptionRefcount(p); |
| 1554 | } |
| 1555 | } |
| 1556 | }); |
| 1557 | } |
| 1558 | ''') |
| 1559 | expected = '''\ |
| 1560 | int, |
| 1561 | char, |
| 1562 | std::runtime_error,abc |
| 1563 | myexception,My exception happened |
| 1564 | char const*, |
| 1565 | ''' |
| 1566 | |
| 1567 | self.do_runf('main.cpp', expected) |
| 1568 |
nothing calls this directly
no test coverage detected