1. 常见的异常类型有哪些呢?
1. 运行时异常
1. ArrayIndexOutOfBoundsException
@Test
public void test1(){
int [] num = new int[10];
System.out.println(num[10]);
}
2. NullPointerException
@Test
public void test2(){
String str = "123";
str = null;
System.out.println(str.toString());
}
3. ClassCastException
@Test
public void test3(){
Object str = new String();
Date date1 = (Date) str;
System.out.println(date1);
}
4. NumberFormatException
@Test
public void test4(){
String str = "abc";
int i = Integer.parseInt(str);
System.out.println(i);
}
5. InputMismatchException
@Test
public void test5(){
Scanner scanner = new Scanner(System.in);
int num = scanner.nextInt();
System.out.println(num);
}
6. ArithmeticException
@Test
public void test6(){
int num = 10;
System.out.println(num / 0);
}