fork/rust
git clone https://git.julia.blue/fork/rust
3bcad65fbf6
master
1#include <cstdio> 2#include <exception> 3 4void println(const char* s) { 5 puts(s); 6 fflush(stdout); 7} 8 9struct outer_exception {}; 10struct inner_exception {}; 11 12extern "C" { 13 void throw_cxx_exception() { 14 if (std::uncaught_exception()) { 15 println("throwing inner C++ exception"); 16 throw inner_exception(); 17 } else { 18 println("throwing outer C++ exception"); 19 throw outer_exception(); 20 } 21 } 22 23 void cxx_catch_callback(void (*cb)()) { 24 try { 25 cb(); 26 println("unreachable: callback returns"); 27 } catch (outer_exception) { 28 println("unreachable: caught outer exception in catch (...)"); 29 } catch (inner_exception) { 30 println("unreachable: caught inner exception in catch (...)"); 31 } 32 } 33}