Skip to content

Instantly share code, notes, and snippets.

@Lovesan
Created June 6, 2019 21:45
Show Gist options
  • Save Lovesan/4a9845a7ab645b4070f1870f57475dd8 to your computer and use it in GitHub Desktop.
Save Lovesan/4a9845a7ab645b4070f1870f57475dd8 to your computer and use it in GitHub Desktop.
A library which throws cross-boundary exceptions
// 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