java异常类
//StackOverflowError 栈溢出
// FileNotFoundExceptoin 文件没找到异常
//ArithmeticException 算术异常
System.out.println(10 / 0);
//ClassCastException 类型转换异常
Object obj = "abc";
Integer i = (Integer)obj;
// InputMismatchException 输入不匹配异常
Scanner sc = new Scanner(System.in);
int val = sc.nextInt();
System.out.println(val);
// NumberFormatException 数字格式异常
//String s = "123a";
String s = "123";
Integer in = Integer.parseInt(s);
System.out.println(in);
// IndexOutOfBoundsException 下标越界异常
int[] arr = new int[3];
System.out.println(arr[0]);
System.out.println(arr[2]);
System.out.println(arr[3]);
自定义异常类
package com.exception;
/**
* 自定义异常类——运行时异常
* @title MyExceptioin.java
*/
public class MyExceptioin extends RuntimeException {
private static final long serialVersionUID = 6379053527480024671L;
public MyExceptioin() {
super();
}
public MyExceptioin(String message) {
super(message);
}
}