为什么捕捉不到分配内存失败的例外,terminate called recursively

ghaiyang 2008-01-10 03:22:18
try{
//myClass类中有hash_map
ptr=new myClass();
}
catch(...){
...
}
代码在linux多线程中,内存不足时,里面分配内存的例外捕捉不到,程序被abort(),gdb调试器里有terminate called recursively输出,想问一下这个内存分配的例外为什么捕捉不到
...全文
1858 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
hai040 2008-01-10
  • 打赏
  • 举报
回复
new不一定会抛异常吧
自已set一个new_handle
ghaiyang 2008-01-10
  • 打赏
  • 举报
回复
has_map<unsigned long long,CLink*>这么用的,CLink*是用new分配的
第二个我试试,谢谢
ryfdizuo 2008-01-10
  • 打赏
  • 举报
回复
1.hash_map在MyClass类里面是怎么使用的?
2.你试着直接定义一个MyClass的对象测试一下,不要用指针去new,
ghaiyang 2008-01-10
  • 打赏
  • 举报
回复
老兄,上千行的代码,独立不出来
重现了一个
Program received signal SIGABRT, Aborted.
[Switching to Thread -1240134736 (LWP 538)]
0x007127a2 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2
(gdb) bt
#0 0x007127a2 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2
#1 0x007567f5 in raise () from /lib/tls/libc.so.6
#2 0x00758199 in abort () from /lib/tls/libc.so.6
#3 0x00c0525b in __gnu_cxx::__verbose_terminate_handler () from /usr/lib/libstdc++.so.6
#4 0x00c02f71 in __cxa_call_unexpected () from /usr/lib/libstdc++.so.6
#5 0x00c02fa6 in std::terminate () from /usr/lib/libstdc++.so.6
#6 0x00c030ef in __cxa_throw () from /usr/lib/libstdc++.so.6
#7 0x00c0353c in operator new () from /usr/lib/libstdc++.so.6
#8 0x08058247 in __gnu_cxx::new_allocator<__gnu_cxx::_Hashtable_node<std::pair<unsigned long long const, CLink*> > >::allocate (this=0x169524c8, __n=1)
at /usr/lib/gcc/i386-redhat-linux/3.4.5/../../../../include/c++/3.4.5/ext/new_allocator.h:81
#9 0x08057aa9 in __gnu_cxx::hashtable<std::pair<unsigned long long const, CLink*>, unsigned long long, hash_u64, std::_Select1st<std::pair<unsigned long long const, CLink*> >, compare_u64, std::allocator<CLink*> >::_M_get_node (this=0x169524c8)
at /usr/lib/gcc/i386-redhat-linux/3.4.5/../../../../include/c++/3.4.5/ext/hashtable.h:252
#10 0x08056a22 in __gnu_cxx::hashtable<std::pair<unsigned long long const, CLink*>, unsigned long long, hash_u64, std::_Select1st<std::pair<unsigned long long const, CLink*> >, compare_u64, std::allocator<CLink*> >::_M_new_node (this=0x169524c8, __obj=@0xb6150250)
at /usr/lib/gcc/i386-redhat-linux/3.4.5/../../../../include/c++/3.4.5/ext/hashtable.h:528
#11 0x080555a2 in __gnu_cxx::hashtable<std::pair<unsigned long long const, CLink*>, unsigned long long, hash_u64, std::_Select1st<std::pair<unsigned long long const, CLink*> >, compare_u64, std::allocator<CLink*> >::insert_unique_noresize (this=0x169524c8,
__obj=@0xb6150250)
at /usr/lib/gcc/i386-redhat-linux/3.4.5/../../../../include/c++/3.4.5/ext/hashtable.h:666
#12 0x0805336d in __gnu_cxx::hashtable<std::pair<unsigned long long const, CLink*>, unsigned long long, hash_u64, std::_Select1st<std::pair<unsigned long long const, CLink*> >, c---Type <return> to continue, or q <return> to quit---
ompare_u64, std::allocator<CLink*> >::insert_unique (this=0x169524c8, __obj=@0xb6150250)
at /usr/lib/gcc/i386-redhat-linux/3.4.5/../../../../include/c++/3.4.5/ext/hashtable.h:383
#13 0x08051ee5 in __gnu_cxx::hash_map<unsigned long long, CLink*, hash_u64, compare_u64, std::allocator<CLink*> >::insert (this=0x169524c8, __obj=@0xb6150250)
at /usr/lib/gcc/i386-redhat-linux/3.4.5/../../../../include/c++/3.4.5/ext/hash_map:169
taodm 2008-01-10
  • 打赏
  • 举报
回复
代码单独拿出来测测呗。
你不贴全代码,谁能帮你。
ghaiyang 2008-01-10
  • 打赏
  • 举报
回复
terminate called recursively//有时候有多个

Program received signal SIGABRT, Aborted.
[Switching to Thread -1325405264 (LWP 603)]
0x007127a2 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2
(gdb) bt
#0 0x007127a2 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2
#1 0x007567f5 in raise () from /lib/tls/libc.so.6
#2 0x00758199 in abort () from /lib/tls/libc.so.6
#3 0x00c052de in __gnu_cxx::__verbose_terminate_handler () from /usr/lib/libstdc++.so.6
#4 0x00c02f71 in __cxa_call_unexpected () from /usr/lib/libstdc++.so.6
#5 0x00c02fa6 in std::terminate () from /usr/lib/libstdc++.so.6
#6 0x00c02622 in __cxa_get_globals () from /usr/lib/libstdc++.so.6
#7 0x00c030d6 in __cxa_throw () from /usr/lib/libstdc++.so.6
#8 0x00c0353c in operator new () from /usr/lib/libstdc++.so.6
下面的有时候可以看出是从hash_map来的,比如在插入时new,不太明白
AlwaysSLH 2008-01-10
  • 打赏
  • 举报
回复
不会吧,先顶一下
taodm 2008-01-10
  • 打赏
  • 举报
回复
那就是没发生异常呗
  • 打赏
  • 举报
回复
访问无效内存 try也不一定能捕获到
所以看看是什么原因引起的.

64,648

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧