C++之try...catch...

以下语句引用HappyTree(笨笨·天行健)在某个问题中的回复。

贴一段来自BS的TCPL话:  
  When   a   program   is   composed   of   separate   modules,   and   especially   when   those   modules   come   from   separately   developed   libraries,   error   handling   needs   to   be   separated   into   two   distinct   parts:  
  [1]   The   reporting   of   error   conditions   that   cannot   be   resolved   locally  
  [2]   The   handling   of   errors   detected   elsewhere  
  The   author   of   a   library   can   detect   run-time   errors   but   does   not   in   general   have   any   idea   what   to   do   about   them.   The   user   of   a   library   may   know   how   to   cope   with   such   errors   but   cannot   detect   them   -or   else   they   would   be   handled   in   the   user's   code   and   not   left   for   the   library   to   find.  
  我想这段话还是比较清楚的。当你写一个库时,比如strcpy,你能检测到运行时错误的存在,但你不知道该如何来做一个通用的处理,这时你就可以抛出一个异常,让调用strcpy的用户来处理。  
  如果你知道如何去处理所有运行时错误,if...else...足够了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值