Skip to content

Instantly share code, notes, and snippets.

@Lovesan
Created June 6, 2019 15:38
Show Gist options
  • Save Lovesan/afb2847962c8873ec4011f0ea3ac20d4 to your computer and use it in GitHub Desktop.
Save Lovesan/afb2847962c8873ec4011f0ea3ac20d4 to your computer and use it in GitHub Desktop.
Example .NET library which internally throws an exception and catches it
// cl.exe /nologo /clr /Od /MD /EHac /LD /Fe:sehlib.dll sehlib_net.cxx
using namespace System;
#include <iostream>
void throws_fn()
{
std::cerr << ".NET throws exception" << std::endl;
throw gcnew Exception();
}
extern "C" __declspec(dllexport) void catches_fn()
{
try
{
throws_fn();
}
catch(Exception^ ex)
{
std::cerr << ".NET catches exception" << std::endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment