C++ display stack trace on exception(C++ 在异常时显示堆栈跟踪)
问题描述
如果抛出异常,我想有一种方法向用户报告堆栈跟踪.做这个的最好方式是什么?是否需要大量额外的代码?
I want to have a way to report the stack trace to the user if an exception is thrown. What is the best way to do this? Does it take huge amounts of extra code?
回答问题:
如果可能的话,我希望它是便携的.我希望弹出信息,以便用户可以复制堆栈跟踪,并在出现错误时通过电子邮件将其发送给我.
I'd like it to be portable if possible. I want information to pop up, so the user can copy the stack trace and email it to me if an error comes up.
推荐答案
这取决于哪个平台.
在 GCC 上,这非常简单,请参阅 这篇文章了解更多详情.
On GCC it's pretty trivial, see this post for more details.
在 MSVC 上,您可以使用 StackWalker 库来处理所有Windows 所需的底层 API 调用.
On MSVC then you can use the StackWalker library that handles all of the underlying API calls needed for Windows.
您必须找出将此功能集成到您的应用程序中的最佳方式,但您需要编写的代码量应该最少.
You'll have to figure out the best way to integrate this functionality into your app, but the amount of code you need to write should be minimal.
这篇关于C++ 在异常时显示堆栈跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C++ 在异常时显示堆栈跟踪
基础教程推荐
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- CString 到 char* 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
