【问题标题】:Get any line number of std:logic_error获取 std:logic_error 的任意行号
【发布时间】:2012-03-25 00:20:55
【问题描述】:

我的 C++ 程序以 std::logic_error 退出,我想追踪导致它的源代码行。我该怎么做?

TBH,我正在使用 gdb,使用 g++ -g 来添加调试信息。我能得到的只有这些消息:

此应用程序已请求运行时以不寻常的方式终止它。 请联系应用程序的支持团队以获取更多信息。 在抛出 'std::logic_error' 的实例后调用终止 what(): basic_string::_S_construct null 无效

Catchpoint 1 (exception thrown), 0x0045ffa0 in __cxa_throw ()
(gdb) bt
#0  0x0045ffa0 in __cxa_throw ()
#1  0x004601e8 in std::__throw_logic_error(char const*) ()
#2  0x00502238 in typeinfo for std::__timepunct<wchar_t> ()
#3  0x004685f8 in std::runtime_error::what() const ()
#4  0x03210da8 in ?? ()
#5  0x002efbcc in ?? ()
#6  0x00468734 in std::domain_error::~domain_error() ()
#7  0x00000000 in ?? ()
(gdb)

【问题讨论】:

    标签: c++ runtime-error


    【解决方案1】:

    您使用调试器。

    使用调试器工具是学习 C 和 C++ 等编译语言的一项非常重要的技能。

    【讨论】:

      【解决方案2】:

      异常对象不携带任何源信息。但是,它们希望包含可以使用what() 成员访问的有用消息。除此之外,您要么必须使用允许在抛出异常时中断的调试器,要么在std::logic_error 的构造函数中设置断点。只要异常是例外的,就可以了。它不适用于在非异常情况下抛出异常的代码。

      【讨论】:

      • 谢谢,你的回答其实是对的,但是我忘了说我正在尝试使用g++和gdb。
      猜你喜欢
      • 2013-01-27
      • 1970-01-01
      • 2011-07-19
      • 1970-01-01
      • 1970-01-01
      • 2011-01-09
      • 2019-04-23
      • 2014-08-04
      • 2016-08-26
      相关资源
      最近更新 更多