error好像没有的 难道说的是编译错误?
Exception、RuntimeException都是exception
try{
}catch(Exception ex){
ex......
}
java.lang.Exception
------java.lang.RuntimeException
RuntimeException是运行时虚拟机的错误,不能被catch
例子如下
class ThrowsRuntimeException {
void excep() {
int i = 10/0; // ArithmeticException
}
}
class ThrowsRuntimeExceptionDemo {
public static void main(String[] args) {
ThrowsRuntimeException obj = new ThrowsRuntimeException();
obj.excep();
}
}
不过可以这样捕捉
class ThrowsRuntimeException3 {
void excep() {
int i = 10/0; // ArithmeticException
}
}
class ThrowsRuntimeExceptionDemo3 {
public static void main(String[] args) {
ThrowsRuntimeException3 obj = new ThrowsRuntimeException3();
try {
obj.excep();
} catch (ArithmeticException e) {
System.out.println("算术例外");
e.printStackTrace();
}
System.out.println("处理结束");
}
} |