社区
系统维护与使用区
帖子详情
g++不支持异常处理 ?
yangrunhua
2000-02-15 05:11:00
有如下:
try
{
char *buffer=new char[1000000000];
if (buffer==NULL)
throw "out of memory";
}
catch(char*string)
{
cout<<string<<endl;
}
运行时竟然结果不是输出out of memory而是Aborted(core dumped)
Why?
...全文
348
7
打赏
收藏
微信扫一扫
点击复制链接
分享
下载分享明细
分享
举报
写回复
7 条
回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
chenshuishui
2001-05-31
同意jansenzhu(),直接试一下
try
{
throw "out of memory";
}
catch(char*string)
{
cout<<string<<endl;
}
打赏
举报
回复
赞
skt642
2001-05-31
67017关注!
打赏
举报
回复
赞
茂奇软件
2000-02-20
[1000000000];
perhaps the interage have overfollow.
you can try it directly.
try
{
throw "out of memory";
}
catch(bad_alloc e) //也可以catch(exception e),e.what()报的信息不同
{
cout<<e.what()<<endl;
}
catch(char*string)
{
cout<<string<<endl;
}
打赏
举报
回复
赞
netmare
2000-02-16
我在linux下试了一下,sintony说的有理,是new时系统throw的异常.
打赏
举报
回复
赞
netmare
2000-02-16
在linux下将程序改为
#include <exception> //注意是exception而不是exception.h
#include <new>
try
{
char *buffer=new char[1000000000];
if (buffer==NULL)
throw "out of memory";
}
catch(bad_alloc e) //也可以catch(exception e),e.what()报的信息不同
{
cout<<e.what()<<endl;
}
catch(char*string)
{
cout<<string<<endl;
}
打赏
举报
回复
赞
sintony
2000-02-15
因为char *buffer=new char[1000000000];
本身就throw "Aborted(core dumped)"
你catch 的是系统的出错信息
打赏
举报
回复
赞
netmare
2000-02-15
core dump可能发生在catch之后,因为cout是带缓冲的,所以未显示出来,用cerr试试.
从你的程序看,catch时除了显示错误信息后未作其他处理,若在catch之后又使用了buffer就会core dump了
打赏
举报
回复
赞
相关推荐
异常
处理
#include
#include
using namespace std; void func1() { //throw string("string"); throw 100; char a='a'; throw a; } void func2() { func1(); } int main() { try{ func2(); }catch(int x) {cout<
关于
异常
处理
的问题?
#include
int main() { cout<<"before the throw statement"<
Solaris 抛出
异常
catch(...)
不
到,core dump了
我写了一个测试
异常
的程序,windows可以正常通过,但是solaris就core dump了, 是
不
是编译器的问题啊,谢谢啦 #include
int main(int argc, char** argv) { try { std::cout << "About to throw exception." << std::endl; throw; } catch(...) { std::cerr << "Exception caught." << std::endl; }
DEBUG时出错,帮忙看看.
#include
// For function prototypes #include
#include
void term_func() { cout << "term_func was called by terminate." << endl; exit( -1 ); } int main() { try { set_unexpected( term_func ); throw "Out of memory!"; } cat
请教gcc的字符指针数组的问题
#include
main() { char *p[] = { "-TEST1","-TEST2",0 }; cout<
发帖
系统维护与使用区
微信扫一扫
点击复制链接
分享社区
下载分享明细
1.9w+
社区成员
7.4w+
社区内容
系统使用、管理、维护问题。可以是Ubuntu, Fedora, Unix等等
社区管理员
加入社区
帖子事件
创建了帖子
2000-02-15 05:11
社区公告
暂无公告