`

异常对照

 
阅读更多
public class TestCuowu {
public static void main(String[] args) {
try{
int a = Integer.parseInt("abc");
}catch(NumberFormatException e){
System.out.println("NumberFormatException");
}
try{
int result = 10/0;
}catch(ArithmeticException e){
//e.printStackTrace();
System.out.println("ArithmeticException");
}
try{
int[] a = new int[5];
int b = a[-1];
int c = a[5];
}catch(ArrayIndexOutOfBoundsException e){
//e.printStackTrace();
System.out.println("ArrayIndexOutOfBoundsException");
}
try{
Object x[] = new String[3];
    x[0] = new Integer(0);
}catch(ArrayStoreException e){
//e.printStackTrace();
System.out.println("ArrayStoreException");
}
try{
Object x = new Integer(0);
    System.out.println((String)x); 
}catch(ClassCastException e){
//e.printStackTrace();
System.out.println("ClassCastException");
}
try{
Class.forName("com.gavin.Test");
}catch(ClassNotFoundException e){
System.out.println("ClassNotFoundException");
}
try{
String a = "123";
a.charAt(-1);
//a.charAt(3);
}catch(StringIndexOutOfBoundsException e){
System.out.println("StringIndexOutOfBoundsException");
}
}
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics