java 19

 1 /*
 2   编译时异常和运行时异常的区别
 3   编译期异常:Java程序必须显示处理,否则程序就会发生错误,无法通过编译
 4   运行期异常:无需显示处理,也可以和编译时异常一样处理
 5  */
 6 import java.text.ParseException;
 7 import java.text.SimpleDateFormat;
 8 import java.util.Date;
 9 public class ExceptionDemo {
10     public static void main(String[] args) {
11         // int a = 10;
12         // int b = 0;
13         // if (b != 0) {
14         // System.out.println(a / b);
15         // }
16 
17         String s = "2014-11-20";
18         // SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
19         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
20         // Date d = sdf.parse(s);
21         try {
22             Date d = sdf.parse(s);
23             System.out.println(d);
24         } catch (ParseException e) {
25             // e.printStackTrace();
26             System.out.println("解析日期出问题了");
27         }
28     }
29 }
何事都只需坚持.. 难? 维熟尔。 LZL的自学历程...只需坚持
原文地址:https://www.cnblogs.com/LZL-student/p/5914493.html