C ++显示异常时的堆栈跟踪 [英] C++ display stack trace on exception

查看:231
本文介绍了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 ++显示异常时的堆栈跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆