是否有一个.net等效于C++意外()/set_unexpected()功能?
编辑:抱歉--我之前省略了一些细节:
语言: C# 2.0
我有一些遗留应用程序,似乎在某个地方抛出一些未处理的异常。我只想把一些东西放在适当的位置,以停止客户的痛苦,直到我能够找到问题的实际来源。在C++中,据我所知,set_unexpected()指向的函数在未处理的异常冒泡到主例程时会被调用。因此,我提出了关于.net等效功能的问题。
发布于 2008-10-29 14:11:09
根据应用程序的类型,有3种可能的处理未处理异常的方案:
免责声明:我不是c++开发人员,但根据我所读到的,这应该可以回答您的问题。
发布于 2012-07-26 09:31:40
在您的混合模式应用程序中,这些处理程序应该捕获大多数意想不到的异常。
private delegate long UnhandledExceptionFilter(IntPtr exception);
[DllImport("KERNEL32.DLL", SetLastError = true)]
private static extern IntPtr SetUnhandledExceptionFilter([MarshalAs(UnmanagedType.FunctionPtr)] UnhandledExceptionFilter filter);
// put these in your bootstrapper
AppDomain.CurrentDomain.UnhandledException += CurrentDomainUnhandledException;
Application.ThreadException += ApplicationThreadException;
SetUnhandledExceptionFilter(UnhandledExceptionFilter);
void CurrentDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
...
}
void ApplicationThreadException(object sender, ThreadExceptionEventArgs e)
{
...
}
long UnhandledExceptionFilter(IntPtr exception)
{
....
}https://stackoverflow.com/questions/246893
复制相似问题