异常的使用场合

什么时候应该用异常,如果不用异常,直接用返回值来代表各种各样的错误是否合理?这个问题曾经在程序语言的学习阶段问过自己,后来也就含糊的理解了。今天看到了MSDN中有这样的一段话,又自己过了一下异常这一个概念,感觉对于加深理解有帮助,MSDN引用如下: When to Use Exceptions Three categories of outcomes can occur when a function is called during program execution: normal execution, erroneous execution, or abnormal execution. Each category is described below. Normal execution The function may execute normally and return. Some functions return a result code to the caller, which indicates the outcome of the… Continue reading 异常的使用场合