Throwable
|--Error 是系统丌可恢复的错误,JVM发生的错误
| |--OutOfMemoryError 堆内存溢出
| |--StackOverflowError 栈内存溢出
|--Exception 程序可以检查处理的异常,常见的异常继承根
|--java.text.ParseException format 解析对象时候发生
| 如:Date d = dateformat.parse("2010-5-5");
|--RuntimeException 非检查异常,Javac忽略对这类异常的语法检查
|--IllegalArgumentException |--NullPointerException *
|--ArrayIndexOutOfBoundsException *
|--ClassCastException *
|--NumberFormatException * Integer.parseInt(S)
/** * 如果try,catch,finally中都有return,则执行finally中的, * 除非System.exit(0)退出程序(System.exit(0)是正常退出程序,而System.exit(1)或者说非0表示非正常退出程序) * */ public String t2(){ try{ return "try"; }catch(Exception e){ return "catch"; }finally { return "finally"; } }
/** * 继承Exception或Throwable,并重写构造方法即可。 * */ public class MyException extends Exception { public MyException() { super(); // TODO Auto-generated constructor stub } public MyException(String message, Throwable cause) { super(message, cause); // TODO Auto-generated constructor stub } public MyException(String message) { super(message); // TODO Auto-generated constructor stub } public MyException(Throwable cause) { super(cause); // TODO Auto-generated constructor stub } }
原文:http://www.cnblogs.com/lovgge/p/5226828.html