Created
June 6, 2019 21:45
-
-
Save Lovesan/4a9845a7ab645b4070f1870f57475dd8 to your computer and use it in GitHub Desktop.
A library which throws cross-boundary exceptions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// g++ -O0 -shared -o unwind.dll unwind.cxx | |
// OR | |
// cl.exe /nologo /Od /MD /EHa /LD /Fe:unwind.dll unwind.cxx | |
#include <iostream> | |
#include <exception> | |
#include <windows.h> | |
class Foo | |
{ | |
public: | |
~Foo() | |
{ | |
std::cerr << "Exiting C++" << std::endl; | |
} | |
}; | |
typedef void(*func)(void*); | |
void throws_fn() | |
{ | |
std::cerr << "C++ throws exception" << std::endl; | |
throw std::exception(); | |
} | |
extern "C" __declspec(dllexport) void catches_fn(func fn) | |
{ | |
Foo foo; | |
try | |
{ | |
fn(throws_fn); | |
} | |
catch(std::exception& e) | |
{ | |
std::cerr << "C++ catches exception" << std::endl; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment