java運行異常分析
來源:文萃谷 1.85W
Java提供了兩類主要的異常:runtime exception和checked exception。checked 異常也就是我們經常遇到的異常,以及SQL異常都是這種異常。以下是小編為大家搜索整理的java運行異常分析,希望能給大家帶來幫助!更多精彩內容請及時關注我們應屆畢業生考試網!
NullPointerException:空指針異常類
示例:
package c;
public class Test {
public static void main(String[] args) {
tln(toUpper(null));
}
public static String toUpper(String str){
return perCase();
}
}
異常信息如下: Exception in thread "main" PointerException
at per()
at (:6)
ArrayIndexOutOfBoundsException:數組下標越界異常
示例:
package c;
public class Test {
public static void main(String[] args) {
int[] a = {0,1,2,3};
tln(a[4]);
}
}
異常信息如下:
Exception in thread "main" yIndexOutOfBoundsException: 4
at (:7)