没有合适的资源?快使用搜索试试~ 我知道了~
Exception Handling: A False Sense of Security
需积分: 9 23 下载量 156 浏览量
2010-11-19
15:26:02
上传
评论
收藏 255KB PDF 举报
温馨提示
试读
9页
c++Exception Handling: A False Sense of SecurityException Handling: A False Sense of SecurityException Handling: A False Sense of Security
资源推荐
资源详情
资源评论
1
This is a slightly modified version of an article that appeared in the November-December 1994 issue of the °C++
Report.
Exception Handling: A False Sense of Security
by °
°°
°Tom Cargill
I suspect that most members of the C++ community vastly underestimate the skills needed to
program with exceptions and therefore underestimate the true costs of their use. The popular belief is
that exceptions provide a straightforward mechanism for adding reliable error handling to our
programs. On the contrary, I see exceptions as a mechanism that may cause more ills than it cures.
Without extraordinary care, the addition of exceptions to most software is likely to diminish overall
reliability and impede the software development process.
This "extraordinary care" demanded by exceptions originates in the subtle interactions among
language features that can arise in exception handling. Counter-intuitively, the hard part of coding
exceptions is not the explicit throws and catches. The really hard part of using exceptions is to write
all the intervening code in such a way that an arbitrary exception can propagate from its throw site to
its handler, arriving safely and without damaging other parts of the program along the way.
In the October 1993 issue of the °
°°
°
C++ Report
, David Reed argues in favor of exceptions saying that:
"Robust reusable types require a robust error handling mechanism that can be used in a consistent
way across different reusable class libraries." While entirely in favor of robust error handling, I have
serious doubts that exceptions will engender software that is any more robust than that achieved by
other means. I am concerned that exceptions will lull programmers into a false sense of security,
believing that their code is handling errors when in reality the exceptions are actually compounding
errors and hindering the software.
To illustrate my concerns concretely I will examine the code that appeared in Reed's article. The code
(page 42, October 1993) is a
Stack class template. To reduce the size of Reed's code for presentation
purposes, I have made two changes. First, instead of throwing
Exception objects, my version simply
throws literal character strings. The detailed encoding of the exception object is irrelevant for my
purposes, because we will see no extraction of information from an exception object. Second, to
avoid having to break long lines of source text, I have abbreviated the identifier current_index to top.
资源评论
车太靓
- 粉丝: 72
- 资源: 41
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功