java常规异常:
有异于常态,和正常情况不一样,有错误出现。阻止当前方法或作用域,称之为异常。
Throwable:
1 Error:
- 虚拟机错误(VirtualMachineError)
- 线程死锁(ThreadDeath)
2 Exception:
-
非检查异常(Runtime Exception)
空指针异常(NullPointException)
String str=null; System.out.println(str.length());
数组下标异常(ArrayIndexOutOfBoundsException)
int[] arry={1,2,3,}; for(int i =0;i<=3;i++){ System.out.println(arry[i]); }
类型转换异常(ClassCastException)
Class Animal{ } class Dog extends Animal{ } class Cat extend Animal{ } public class Test{ Animal a1=new Dog (); Animal a2=new Cat (); Dog d1=(Dog)a1; Dog d2=(Dog)a2; }
算数异常(ArithmeticException)
int one=12; int two=0; System.out.println(one/two);
-
检查异常
文件异常(IOExecption)
SQL异常(SQLException)