5章 错误处理方法.pptVIP

  • 7
  • 0
  • 约8.2千字
  • 约 37页
  • 2018-10-13 发布于山东
  • 举报
5章 错误处理方法.ppt

注意 错误处理代码通常比一般代码更难和不易理解 通常正确的代码给出一种输出 而错误的代码会产生不同的错误输出 如果更多的人使用这个程序,则错误处理应做得更好 当代码供自己使用时,错误是自已的问题 当代码供朋友使用时,错误会让你失去朋友 当代码被其他不认识的人使用时,错误会让他们很伤心 他们不知道如何修复这个错误 * 前置条件 函数需要的参数是什么? 这种需要通常称为前置条件 检查函数的参数是一个好办法 int area(int length, int width) // 计算矩形的面程 // length and width must be positive { if (length=0 || width =0) throw Bad_area(); return length*width; } * 后置条件 必须确定函数的返回值是什么? 这种检查称为后置条件 int area(int length, int width) // calculate area of a rectangle // length and width must be positive { if (length=0 || width =0) throw Bad_area(); // the result must be a positive int that is the are

文档评论(0)

1亿VIP精品文档

相关文档