2016 February 29 Java
Java异常处理
捕获和处理异常
在Java中用try…catch来捕获和处理异常; finally关键字用来创建在try代码块后面执行的代码块。
无论是否发生异常,finally代码块中的代码总会被执行。 在finally代码块中,可以运行清理类型等收尾善后性质的语句。
throw和throws关键字
throws是指当前方法不处理异常,,而是交给调用这个方法的方法去处理异常
throw直接抛出一个异常
Exception 和 RantimeException的区别
Exception是_检查型_异常,例如Exception,在程序中必须要用try…catch进行处理 RantimeException是_非检查型_异常(运行时异常),例如NumberFormatExpection,可以不用try…catch进行处理,但是如果产生异常,则异常又JVM进行处理(Java异常处理机制) 检查或不检查指在编译时 RumtimeException最好也由try…catch进行处理
自定义异常