摘要: RumtimeException是一种UncheckedException。UncheckException是一种不需要在方法签名中声明的异常类型。广为知道的RuntimeException的子类有NullPointerException,StringOutOfBoundsException。ArrayIndexOutOfBoundsException之类的。在代码运行的过程中由于变量为空或者数组越界等情况就会发生这种异常。当异常发生的时候,由于没有try-catch会产生程序意外退出的情况。为了避免发生这种异常而导致应用程序意外退出,需要对代码进行try-catch或者是在调用前进行非空判定 阅读全文
posted @ 2012-11-18 21:38 史蒂芬.王 阅读(1606) 评论(1) 推荐(0) 编辑
摘要: 自表达代码的的特点1. 代码的返回值意思明确看一个报名程序的书写,这是采用非自表达方式书写的。 1 public String registerLesson(int userId, int lessonId) { 2 int code = checkUserId(userId); 3 if (code != 0) { 4 return "user does not exist."; 5 } 6 7 code = checkLessonId(lessonId); 8 if (code != 0) { 9 return "l... 阅读全文
posted @ 2012-11-18 20:35 史蒂芬.王 阅读(345) 评论(1) 推荐(1) 编辑