gpt4 book ai didi

c++ - 是否可以使用调试器调试 UnhandledExceptionFilters?

转载 作者:可可西里 更新时间:2023-11-01 11:54:23 25 4
gpt4 key购买 nike

在 Microsoft Windows API 中,您可以使用 SetUnhandledExceptionFilter , 为未处理的异常设置处理程序。该页面上提到的最大收获是:

If an exception occurs in a process that is not being debugged, and the exception makes it to the unhandled exception filter, that filter will call the exception filter function specified by the lpTopLevelExceptionFilter parameter.

(添加了强调)

这基本上意味着,如果进程正在调试,调试器会收到异常,并且我的过滤器会被跳过!

我可以使用 printfs 和试错法以老式方式测试和调试我的 ExceptionFilter。

但是我错过了什么吗?如果在调试器中禁用了 ExceptionFilter,是否有交互式调试 ExceptionFilter 的好方法?

最佳答案

查看 KB173652 的解决方案部分其中谈到将 main/WinMain 中的所有代码放在 _try/_except block 中,如下所示。

void main (int argc, char **argv)
{
__try
{
// all of code normally inside of main or WinMain here...

}
__except (MyUnFilter (GetExceptionInformation()))
{
OutputDebugString ("executed filter function\n");
}
}

另一篇文章,Debugging custom filters for unhandled exceptions ,描述了除上述技术之外的更多技术。我个人使用的是在异常过滤器中显示消息框然后附加调试器的方法。我用 IsDebuggerPresent判断是否显示消息框。

关于c++ - 是否可以使用调试器调试 UnhandledExceptionFilters?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20981982/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com