Skip to content

Instantly share code, notes, and snippets.

@Lovesan
Created June 6, 2019 15:37
Show Gist options
  • Save Lovesan/2b97d390898ac760629d661b6a466151 to your computer and use it in GitHub Desktop.
Save Lovesan/2b97d390898ac760629d661b6a466151 to your computer and use it in GitHub Desktop.
Example C++ library which internally throws an exception and catches it
// 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