C++异常处理导致终止

发布于 2024-12-12 02:54:52 字数 660 浏览 0 评论 0原文

我们在 C++ 代码中遇到一个问题。当抛出异常时 进程正在终止,但我的代码有适当的异常 处理。

   Core stack is below.
   ======================
   #0  0xffffe410 in __kernel_vsyscall ()
   #1  0x00489915 in raise () from /lib/tls/libc.so.6
   #2  0x0048b379 in abort () from /lib/tls/libc.so.6
   #3  0xf6a1fbdb in __gnu_cxx::__verbose_terminate_handler () from /usr/lib/libstdc++.so.6
   #4  0xf6a1d8f1 in __cxa_call_unexpected () from /usr/lib/libstdc++.so.6
   #5  0xf6a1d926 in std::terminate () from /usr/lib/libstdc++.so.6
   #6  0xf6a1da6f in __cxa_throw () from /usr/lib/libstdc++.so.6

一些论坛表明,当处理其他异常时出现堆栈展开或引发异常时,可能会发生这种情况。

您能在这里提出建议来解决这个问题吗?

We are facing a problem in c++ code.When an exception is thrown the
process is getting terminated,but my code has proper exception
handling.

   Core stack is below.
   ======================
   #0  0xffffe410 in __kernel_vsyscall ()
   #1  0x00489915 in raise () from /lib/tls/libc.so.6
   #2  0x0048b379 in abort () from /lib/tls/libc.so.6
   #3  0xf6a1fbdb in __gnu_cxx::__verbose_terminate_handler () from /usr/lib/libstdc++.so.6
   #4  0xf6a1d8f1 in __cxa_call_unexpected () from /usr/lib/libstdc++.so.6
   #5  0xf6a1d926 in std::terminate () from /usr/lib/libstdc++.so.6
   #6  0xf6a1da6f in __cxa_throw () from /usr/lib/libstdc++.so.6

Some of the forums showing that this might occur when there is a stack unwinding or exception raised when handling other exception.

Can you please suggest here to fix the problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

因为看清所以看轻 2024-12-19 02:54:53

如果/当无法为将引发的依赖异常对象分配内存时,也可能会导致此问题。 (我想这种情况很少见。但这可能是应用程序异常终止的原因。)

Can also be caused if/when cannot allocate memory for a dependent exception object which would be thrown. (I imagine this is rare. But is possible reason the app would terminate abnormally.)

有深☉意 2024-12-19 02:54:52

如果满足以下条件,则可以调用 Terminate:

  • 在传播另一个异常时引发异常
  • 引发违反异常规范的异常
  • 引发异常但从未捕获

但您的调用堆栈还存在意外 =>__cxa_call_unexpected ()

对我来说,这表明违反了异常规范。
这会调用unexpected(),默认情况下会调用terminate()。

Terminate can be called if:

  • An exception is thrown while another exception is propagating
  • An exception is thrown that violates an exception specification
  • An exception is thrown and never caught

But your call stack also has unexpected =>__cxa_call_unexpected ()

To me this is an indication that an exception specification has been violated.
This calls unexpected() which by default calls terminate().

娇纵 2024-12-19 02:54:52

您是否在任何对象析构函数中抛出异常?在 *nix 系统中,当捕获当前异常之前抛出新异常时,通常会调用终止。

当抛出异常时,堆栈帧中的对象会随着堆栈展开而被销毁。如果这些对象中的任何一个在销毁期间抛出异常,则会混淆异常处理机制,因为它现在有两个异常需要捕获,即原始异常和在堆栈上的对象销毁期间抛出的新异常。因此它发出终止并中止。

Are you throwing an exception in any of your object destructors? A call to terminate generally happens in *nix systems when a new exception is thrown before the current exception is caught.

When an exception gets thrown the objects in your stack frame get destroyed as the stack unwinds. If any of these objects were to throw an exception during destruction, it confuses the exception handling mechanism as it has now two exceptions to catch, the original exception and the new one which gets thrown during the destruction of the object on the stack. So it issues a terminate and aborts.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文