Exceptions

【定义】

error: external, like out of memory

exception: internal, like file not found

父类都是throwable 逻辑有错是runtimeerror

 

【是否check】

unchecked types: error, run time exception

how to solve checked: catch, specify

 

【处理方法】

Scanner input = new  Scanner(new File(filename)); 必须要有

file not found exception

【exception处理情景】

 

顺序:从特殊到一般,最特殊的是3,先处理3

 

 

【Custom exceptions 自定义异常】

可能会抛出或捕获运行时异常,但编译器不会检查它们

从try-block抛出异常时,它可以被任何catch块捕获和处理
从catch块中抛出异常时,它不能被同一级别的其他catch块捕获。 在catch-block中创建一个嵌套的try-catch块,以在内部catch块中处理它。

 自定义的Exception要加new 

throw new MyException()

原文地址:https://www.cnblogs.com/immiao0319/p/9873157.html