C++异常处理导致终止
我们在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果/当无法为将引发的依赖异常对象分配内存时,也可能会导致此问题。 (我想这种情况很少见。但这可能是应用程序异常终止的原因。)
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.)
如果满足以下条件,则可以调用 Terminate:
但您的调用堆栈还存在
意外
=>__cxa_call_unexpected ()
对我来说,这表明违反了异常规范。
这会调用unexpected(),默认情况下会调用terminate()。
Terminate can be called if:
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().
您是否在任何对象析构函数中抛出异常?在 *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.