Created
June 6, 2019 15:37
-
-
Save Lovesan/2b97d390898ac760629d661b6a466151 to your computer and use it in GitHub Desktop.
Example C++ library which internally throws an exception and catches it
This file contains 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 sehlib.dll sehlib.cxx | |
// OR | |
// cl.exe /nologo /Od /MD /EHac /LD /Fe:sehlib.dll sehlib.cxx | |
#include <iostream> | |
#include <exception> | |
void throws_fn() | |
{ | |
std::cerr << "C++ throws exception" << std::endl; | |
throw std::exception(); | |
} | |
extern "C" __declspec(dllexport) void catches_fn() | |
{ | |
try | |
{ | |
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