1、java.lang.ArithmeticException
算術運算異常,因爲除數爲0,所以引發了算數異常
2、Java.lang.StringIndexOutOfBoundsException: String index out of range: -1
這是截取字符串substring()產生的下標越界異常。原因是可能是字符串爲空,或長度不足1
3、java.lang.NullPointerException空指針異常
出現該異常的原因在於某個引用爲null,但卻調用了它的某個方法,這時就會出現該異常
4、ClassCastException
類型強制轉換異常,例如:Object x = new Integer(0);System.out.println((String)x);
5、IllegalArgumentException
傳遞非法參數異常,此異常表明向方法傳遞了一個不合法或不正確的參數。你看看傳值的方法是否參數不正確
6、NumberFormatException
數字格式異常,例如:把"176//240"這個輸入字條轉換爲一個數字
7、ClientAbortException: java.io.IOException異常
原因是由於服務器正在處理http請求,正在輸出內容時,用戶關閉了瀏覽器,造成了ClientAbortException異常。它屬於I/O異常中比較常見的一種。
8、ClientAbortException Caused by: java.NET.SocketException: Connection reset by peer: socket write error
這種異常已比較常見,通常有以下幾種情況:
服務器的併發連接數超過了其承載量,服務器會將其中一些連接Down掉;客戶關掉了瀏覽器,而服務器還在給客戶端發送數據
9、ArrayStoreException
向數組中存放與聲明類型不兼容對象異常,例如:Object x[] = new String[3];x[0] = new Integer(0);
10、NegativeArraySizeException
創建一個大小爲負數的數組錯誤異常,例如int[] arr = new int[10];int i = arr[-1];
11、SecurityException
安全異常,例如:Android的權限異常,運行java的程序提示Missing requited Permissions manifest attribute in main jar等
12、UnsupportedOperationException
不支持的操作異常,例如String testStr = "100,300,400,545,666";List<String> test = Arrays.asList(testStr.split(","));test.remove("100");使用Arrays.asList()方法一定要注意類型的轉換。
Java中的異常分爲兩大類:
1.Checked Exception(非Runtime Exception)
2.Unchecked Exception(Runtime Exception)
運行時異常
RuntimeException類是Exception類的子類,它叫做運行時異常,Java中的所有運行時異常都會直接或者間接地繼承自RuntimeException類。
Java中凡是繼承自Exception,而不繼承自RuntimeException類的異常都是非運行時異常。附一張java異常機制圖
原文地址:http://blog.csdn.net/qq_17168031/article/details/51433849