异常: 程序的正常流程被中断的事件。
try...catch...finally...throw...throws(方法定义时使用)
try{
...
}catch (Throwable t){
t.printStackTrace();
}
class SelfDefineEx extends Exception{
public SelfDefineEx(){
}
public SelfDefineEx(String msg){
super(msg);
}
}
public void method() throws SelfDefineEx{
if (){
throw new SelfDefineEx("self define ex");
}
}
try{
method();
}catch (SelfDefineEx e){
sout(e.getMessage());
e.printStackTrace();
}
Throwable:
1) Error ->
VirtualMachineError: StackOverflowError, OutOfMemoryError
AWTError
2) Exception:
RuntimeTimeException: ArithmeticException, NullPointerException, IndexOutOfBoundsException. IndexIsNegativeException, IndexOutOfRangeException
IOException: EOFException, FileNotFoundException