从 catch 块获取回溯
我正在使用 backtrace 从异常位置获取信息被抛出。在异常的构造函数中,我将回溯存储在 std::string 中,并在此类异常的 catch 块中打印此回溯。
但我想知道,是否有可能以某种方式在其他异常类型的 catch 块中获得相同的回溯?
I am using backtrace to get the information from where the exception is thrown. In the constructor of my exception, I am storing the backtrace in a std::string, and in the catch block for exceptions of this type, I am printing this backtrace.
But I was wondering, is it possible to somehow get the same backtrace in the catch block for other exception types?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能对正在开发的 Boost 库感兴趣:Portable Backtrace 。示例:
打印:
希望这有帮助!
You might be interested in a Boost library under development: Portable Backtrace. Example:
Prints:
Hope this helps!
我不这么认为。当执行程序在 catch 块中停止时,堆栈将展开,并且之前发生的所有内容都不再位于堆栈中。
I don't think so. When executons stops in catch block the stack is unwound, and all that has happened before is not in stack anymore.
相关类是否有一个可以编辑的共同基础?
否则,我在 每次在 Visual C++ 程序中抛出异常时如何运行一些代码? ;-P 其他一些人也发表了意见。
Do the classes in question share a common base you can edit?
Otherwise, I provided a wonderful but terribly underappreciated answer at How can some code be run each time an exception is thrown in a Visual C++ program? ;-P Some others opined too.