標籤:alt stat 虛擬 ram not comment sql exce ring
java的錯誤分類
java中的錯誤分為兩大類:Error和Exception錯誤。
Error 是程式無法處理的錯誤,表示運行應用程式中較嚴重問題,修改程式本身是不能解決的。例如java運行時產生的系統內部錯誤(虛擬機器錯誤),資源耗盡導致的錯誤。
Exception是異常類,它表示程式本身可以處理的錯誤。主要分為非運行異常和運行異常。
1.非運行時異常(編譯異常)
IOException異常
表示由失敗或中斷的I / O操作產生的異常類。
SQLException異常
表示訪問資料庫錯誤或者資料庫資訊錯誤。
2.運行時異常(RuntimeException)
常見的運行時異常:
ClassCastException(類轉換異常) public class Demo{ public static void main(String[] args){ Object x = new Integer(0); System.out.println((String)x); }}
StringIndexOutOfBoundsException(字串角標越界異常)
public class Demo { public static void main(String[] args){ String s = "abcdefg"; System.out.print(s.charAt(9)); }}
ArrayIndexOutOfBoundsException(數組角標越界異常)
public class Demo { public static void main(String[] args){ int [] arr = new int[4]; System.out.println("arr[0]="+arr[4]); }}
NullPointerException(null 指標異常)
public class HelloWorld{ public static void main(String[] args){ int [] arr = new int[4]; arr[0] = 5; System.out.println("arr[0]="+arr[0]);
arr = null;System.out.println("arr[0]="+arr[0]);//報錯 }}
ArrayStoreException(資料存放區異常,運算元組時類型不一致)
public class Test{public static void main(String[] args){ Object x[] = new String[3]; x[0] = new Integer(0); System.out.println(x[0]); }}
ArithmeticException(算術異常)
public class FindError { public static void main(String[] args){ int x = 4,y = 0; int result = x / y; System.out.print(result); }}
java的錯誤分類