免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
123
最近访问板块 发新帖
楼主: xyk6
打印 上一主题 下一主题

大家在项目代码中经常使用异常处理么? [复制链接]

论坛徽章:
0
21 [报告]
发表于 2009-01-21 13:18 |只看该作者

回复 #19 eveson 的帖子

不过标准 C 可以用 <setjmp.h> 来实现类似异常处理的功能。
The typical use for setjmp/longjmp is for exception handling — by calling longjmp, the program can jump out of many levels of nested function calls without having to go to the trouble of setting flag variables which need to be checked in each function. A problem with the use of setjmp/longjmp is that cleanup (such as closing file descriptors, flushing buffers, freeing heap-allocated memory, etc.) is not conducted automatically.

http://en.wikipedia.org/wiki/Longjmp



[ 本帖最后由 langue 于 2009-1-21 13:23 编辑 ]

论坛徽章:
0
22 [报告]
发表于 2009-01-21 13:25 |只看该作者
原帖由 langue 于 2009-1-21 13:18 发表
不过标准 C 可以用  来实现类似异常处理的功能。

http://en.wikipedia.org/wiki/Longjmp



Nod.

论坛徽章:
0
23 [报告]
发表于 2009-01-21 13:27 |只看该作者
原帖由 orbitadam 于 2008-12-24 13:13 发表
比如new之类有可能抛出异常,必须抓异常。至于自己,从不抛异常。


谁说的?
如果这样用
#include <new>

function foo()
{
&nbsp;&nbsp;type = new(std::nothrow) type;
}


是不抛异常的。

论坛徽章:
0
24 [报告]
发表于 2009-01-30 16:32 |只看该作者
原帖由 langue 于 2009-1-21 13:18 发表
不过标准 C 可以用  来实现类似异常处理的功能。

http://en.wikipedia.org/wiki/Longjmp




给个例子看看哈

论坛徽章:
0
25 [报告]
发表于 2009-02-12 10:49 |只看该作者
原帖由 李某人 于 2009-1-30 16:32 发表



给个例子看看哈


点进去,里面的例子还不够么?

论坛徽章:
0
26 [报告]
发表于 2009-02-12 15:03 |只看该作者
分工明确、责权分明是工作能顺利进行的必要保证。
异常就是硬件设计不良引起的,是硬件人员的失职所致,与软件无关,应该追究硬件人员的责任。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP