免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3769 | 回复: 5
打印 上一主题 下一主题

try-catch为何没起作用?(g++) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-06-28 14:39 |只看该作者 |倒序浏览
  1. #include <stdio.h>;

  2. int main(int argc, char *argv[])
  3. {
  4.     try {
  5.         int b = 0;
  6.         int c;

  7.         c = 9/b;
  8.     }   catch(...) {
  9.         printf("I've got you!\n");
  10.     }

  11.     return 0;
  12. }
复制代码


编译
  1. g++ -o try-catch try-catch.cpp -g -Wall -fexceptions
复制代码

运行 ./try-catch,结果是
Floating point exception
而不是
I've got you!

哪位兄弟给指点一下?

论坛徽章:
2
亥猪
日期:2014-03-19 16:36:35午马
日期:2014-11-23 23:48:46
2 [报告]
发表于 2005-06-28 15:12 |只看该作者

try-catch为何没起作用?(g++)

This is C++, not Java, anything you must do by yourself,that is the exceptional run-time detecter must established by yourself not the OS which just maintains the run-time enviroment. You abuse the "try-catch" statement,and should find some textbooks to clarify the concepts you once keep in Java mind.

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
3 [报告]
发表于 2005-06-28 15:18 |只看该作者

try-catch为何没起作用?(g++)

楼主的代码实在牛.
让我这样的小辈看不懂.

论坛徽章:
0
4 [报告]
发表于 2005-06-28 16:15 |只看该作者

try-catch为何没起作用?(g++)

如果你有兴趣,可以写一个异常类,捕获SIGFPE,然后抛出浮点异常,这样你的愿望就可以实现了。

论坛徽章:
0
5 [报告]
发表于 2005-06-28 16:59 |只看该作者

try-catch为何没起作用?(g++)

哎呀,被VC误导了!
VC用try是可以捕捉到runtime error的。所以偶就一直认为这是c++的标准。

BTW: 其实我一直是Cer,不是JAVAer。C++用的也不多。没怎么完整地看过介绍C++的书。

论坛徽章:
0
6 [报告]
发表于 2005-06-28 17:00 |只看该作者

try-catch为何没起作用?(g++)

我的天 9/0 够狠
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP