11.8 RuntimeException

发布时间 2023-07-02 11:37:30作者: 盘思动

demo1 parseInt() 方法不处理异常

public class JavaDemo {
	public static void main(String args[]) {
		int num = Integer.parseInt("123");// 课程中从官网手册,查看parseInt方法,使用RuntimeException,非强制处理异常
		System.out.println(num);
	}
}

面试题:请解释RuntimeException与Exception的区别?
1.RuntimeException是Exception的子类
2.RuntimeException 标注的异常不需要强制进行处理,Exception标注的异常必须强制处理.
3.常见的RuntimeException异常:NumberFormatException,ClassCastException