本节课视频:
『阿男的Java小课堂』*04*Exception与Error
Throwable的设计:
Error与RuntimeException是unchecked exception。
Error一般由JDK定义内部使用:
RuntimeException用于定义运行时发生的
错误:
其它Exception是Checked Exception,需要try...catch:
class="java">
/**
* Created by weli on 5/18/16.
*/
public class PlayWithExceptions {
public static void foo() throws RuntimeException {
}
public static void bar() throws Error {
throw new StackOverflowError();
}
public static void xyz() throws Exception {
}
public static void main(String[] args) {
foo();
bar();
try {
xyz(); // checked exception
} catch (Exception e) {
// deal with the Exception
}
}
}
- 大小: 118.8 KB
- 大小: 116.4 KB
- 大小: 116.3 KB