关于 C++ 的 “异常”
时间:2010-04-29 来源:buxoman
今天重新翻开C++之父写的《TCPL》特别版,打开到第14章。
这一章开宗明义,提出了异常这种机制是为了解决什么问题的:
"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 have been handled in the user's code and not left for the library to find. The notion of an exception is provided to help deal with such problems."
后来进一步明确异常的适用范围:"In particular, it is intended to support error handling in programs composed of independently developed components."
对异常的实现机制有一个论述:"The exception-handling mechanism is a nonlocal control structure based on stack unwinding that can be seen as an alternative return mechanism."
总的看来,异常也不是到处适用的。或许对于直接使用第三方库的用户比较好吧。
这一章开宗明义,提出了异常这种机制是为了解决什么问题的:
"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 have been handled in the user's code and not left for the library to find. The notion of an exception is provided to help deal with such problems."
后来进一步明确异常的适用范围:"In particular, it is intended to support error handling in programs composed of independently developed components."
对异常的实现机制有一个论述:"The exception-handling mechanism is a nonlocal control structure based on stack unwinding that can be seen as an alternative return mechanism."
总的看来,异常也不是到处适用的。或许对于直接使用第三方库的用户比较好吧。
相关阅读 更多 +