- 是程序中的不正常事件,不包括语法错误和逻辑错误
- Error(错误):Java虚拟机不能解决严重问题
- Exception(异常):外在因素或编译错误一般性问题
- 异常分运行时异常(可以不处理)和编译时异常(必须处理)
public class Exception00 {
public static void main(String[] args) {
//no1
Integer[] integers = new Integer[3];
integers[4] = 4;
//no2
System.out.println(1 / 0);
//no3
A b = new B();
B b2 = (B)b;
C c = (C)b;
//no4
String a = null;
System.out.println(a.length());
//no5
String name = "smith";
int i = Integer.parseInt(name);
System.out.println(i);
}
}
class A{}
class B extends A{}
class C extends A{}
处理异常
throws
try - catch (ctrl + alt + j)
public class Throws_ {
public static void main(String[] args) throws Exception{
try {
System.out.println(1 / 0);
} catch (Exception e) {
e.printStackTrace();
}finally {
System.out.println("!!!");
}
}
}
System.out.println("!!!");
}
}
}



