RuntimeException
不需要强制对其进行声明和捕获。可以认为Checked exception
就是要强制程序员去处理这个异常(不管你throws
多少层,终归要在某个地方catch
),而Runtime exception
则没有这个限制,可以自由选择是否catch
。
// 定义的是一个必检异常
class HexFormatException extends Exception { }
// 定义的是一个运行时异常
class BinaryFormatException extends NumberFormatException {}
NumberFormatException extends IllegalArgumentException
IllegalArgumentException extends RuntimeException
0 条评论