File size: 718 Bytes
0284885 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | package Exception_package1;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Exception_demo1 {
public static void main(String[] args) throws ParseException {
//编译时异常(在编译阶段,必须要手动处理,否则代码报错)
String time = "2030年1月1日";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
Date date = sdf.parse(time);
System.out.println(date);
//运行时异常(在编译阶段是不需要处理的,是代码运行时出现的异常)
int[] arr = {1, 2, 3, 4, 5};
System.out.println(arr[10]);//ArrayIndexOutOfBoundsException
}
}
|