java运行异常分析
Java提供了两类主要的异常:runtime exception和checked exception。checked 异常也就是我们经常遇到的`IO异常,以及SQL异常都是这种异常。以下是小编为大家搜索整理的java运行异常分析,希望能给大家带来帮助!更多精彩内容请及时关注我们应届毕业生考试网!
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:数组下标越界异常
示例:
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)