This is in the context of a library written in C++/CLI.
It passes a function to call_in_appdomain, and if that function throws a managed exception, it will catch it, convert it to an hresult, and then convert that hresult into another managed exception it throws. Usually, the caller hasn't set up any exception handlers (it has a C interface), and so this will crash the process, with a stack trace that points to where it throws the re-constituted exception.
In our use-case, we don't expect the passed function to throw any exceptions, so I wanted to write a wrapper that calls the original function, and crashes if any exception was thrown.
My first attempt at this was something like
try
{
// Adding the try/catch at this level instead of the impl. of OriginalFn() since that's compiled as vanilla C++, so can't (easily?) deal with managed exceptions (it calls other functions which may throw managed exceptions, so we want to crash if that happens since that'll prevent destructors from being called)
return OriginalFn();
}
catch (...)
{
__fastfail(FAST_FAIL_FATAL_APP_EXIT);
}
but the issue is that the stack trace of the crashed process is in the catch block; it has already lost the context of where the unexpected exception was thrown.
Is there some way I can make it work as if there were no compatible exception handler on the stack, and have the stack trace of the crashed process show where the original offending exception was thrown? Essentially I want it to act as if it were being called from main(), so there were no 'compatible' exception handlers on the stack