java運(yùn)行異常分析
Java提供了兩類主要的異常:runtime exception和checked exception。checked 異常也就是我們經(jīng)常遇到的`IO異常,以及SQL異常都是這種異常。以下是小編為大家搜索整理的java運(yùn)行異常分析,希望能給大家?guī)韼椭?更多精彩內(nèi)容請(qǐng)及時(shí)關(guān)注我們應(yīng)屆畢業(yè)生考試網(wǎng)!
NullPointerException:空指針異常類
示例:
package com.darkmi.basic;
public class Test {
public static void main(String[] args) {
System.out.println(toUpper(null));
}
public static String toUpper(String str){
return str.toUpperCase();
}
}
異常信息如下: Exception in thread "main" java.lang.NullPointerException
at com.darkmi.basic.Test.toUpper(Test.java:11)
at com.darkmi.basic.Test.main(Test.java:6)
ArrayIndexOutOfBoundsException:數(shù)組下標(biāo)越界異常
示例:
package com.darkmi.basic;
public class Test {
public static void main(String[] args) {
int[] a = {0,1,2,3};
System.out.println(a[4]);
}
}
異常信息如下:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
at com.darkmi.basic.Test.main(Test.java:7)