72、java异常-Throwable

来源:互联网 发布:mac火狐兼容性视图设置 编辑:程序博客网 时间:2024/05/18 13:07
Throwable中的方法1、public String getMessage():异常的消息字符串 2、public String toString():返回异常的简单信息描述 此对象的类的 name(全路径名)  ": "(冒号和一个空格)   调用此对象 getLocalizedMessage()方法的结果 (默认返回的是getMessage()的内容) 3、printStackTrace() 获取异常类名和异常信息,以及异常出现在程序中的位置。返回值void。把信息输出在控制台。public class ExceptionDemo {public static void main(String[] args) {String s = "2014-11-20";SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");try {Date d = sdf.parse(s); // 创建了一个ParseException对象,然后抛出去,和catch里面进行匹配System.out.println(d);} catch (ParseException e) { // ParseException e = new ParseException();// getMessage()// System.out.println(e.getMessage());//Unparseable date: "2014-11-20"// toString()// System.out.println(e.toString());// java.text.ParseException: Unparseable date: "2014-11-20"e.printStackTrace();//java.text.ParseException: Unparseable date: "2014-11-20"//at java.text.DateFormat.parse(DateFormat.java:357)//at cn.itcast_04.ExceptionDemo.main(ExceptionDemo.java:24)}System.out.println("over");}}

原创粉丝点击