可以从Windows SEH异常解码C异常吗? (如果是,怎么样?)
发布时间:2020-12-13 19:47:40 所属栏目:Windows 来源:网络整理
导读:如果出现未处理的C异常,我想打印: 消息(what())的C异常 堆栈跟踪. 为了获取堆栈跟踪,我使用SetUnhandledExceptionFilter与StackWalker库结合使用: struct FooStackWalker : StackWalker{ virtual void OnCallstackEntry(CallstackEntryType,CallstackEntry
如果出现未处理的C异常,我想打印:
>消息(what())的C异常 为了获取堆栈跟踪,我使用SetUnhandledExceptionFilter与StackWalker库结合使用: struct FooStackWalker : StackWalker { virtual void OnCallstackEntry(CallstackEntryType,CallstackEntry &entry) override { std::cerr << entry.lineFileName << " (" << entry.lineNumber << "): " << entry.undFullName << std::endl; } }; LONG WINAPI UnhandledExceptionHandler(LPEXCEPTION_POINTERS pointers) { FooStackWalker walker; walker.ShowCallstack(::GetCurrentThread(),pointers->ContextRecord); ::TerminateProcess(::GetCurrentProcess(),1); } int main() { ::SetUnhandledExceptionFilter(UnhandledExceptionHandler); } 我已经得到堆栈跟踪打印很好,但现在得到什么困难. 有一些方法可以将SEH异常解码为C异常,以便在终止之前调用此成员函数?
为什么不使用已经给你异常细节的C机器?它不是排他性的SEH过滤器(虽然它是独家的SetUnhandledExceptionFilter).你只需要正确地嵌套处理程序:
int main() { try { return cppexcept_main(); } catch (const std::exception& e) { //use e.what() } } int cppexcept_main() { __try { return application_main(); } __except(GrabStackTrace(GetExceptionInformation()),EXCEPTION_CONTINUE_SEARCH) { /* never reached due to EXCEPTION_CONTINUE_SEARCH */ } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 虚拟化 – 连接到域中的其他Hyper-V Manager实例
- windows – 强制批处理文件对提示回答“是”
- 有没有办法在WIndows操作系统上使用UNIX GREP命令
- 从.Net托管代码加载32或64位DLL
- windows-server-2008-r2 – 提供大量文件的最佳实践
- windows-server-2008 – 防火墙阻塞/解除端口[封闭]
- 怎么在windows10中关闭Windows Defender?
- 在windows dos shell下使用参数执行Perl脚本的正确命令行是
- windows-server-2003 – 在潜在的恶意网络上保护Active Dir
- Windows机器的正常运行时间
推荐文章
站长推荐
热点阅读