Red*_*dog 5 .net c++ delegates managed-c++ exception
我有非托管C++通过Marshal :: GetFunctionPointerForDelegate提供的函数指针调用托管委托.该委托有可能抛出异常.我需要能够在我的非托管C++中正确处理此异常,以确保指针清理等内容,并可能将异常重新抛出到更多托管代码中.调用堆栈类似于:
托管代码 - >非托管C++ - >通过委托回调托管代码(可以抛出异常).
任何人都有指针正确处理这种情况,以便可以清理非托管代码中的资源,并可以将一个可用的异常抛出到启动整个调用堆栈的托管代码?
从托管代码中捕获
try
{
throw gcnew InvalidOperationException();
}
catch(InvalidOperationException^ e)
{
// Process e
throw;
}
Run Code Online (Sandbox Code Playgroud)
和
[assembly:RuntimeCompatibility(WrapNonExceptionThrows = true)];
Run Code Online (Sandbox Code Playgroud)
在您的程序集中捕获托管和非托管异常