@TryLoveCatch
2022-04-19T09:28:51.000000Z
字数 1779
阅读 898
Java知识体系
Java 异常类层次结构图概览 :

Exception和Error都是继承了Throwable类,在Java中只有Throwable类型的实例才可以被抛出(throw)或者捕获(catch),它是异常处理机制的基本组成类型。
Exception又分为可检查(checked)异常和不检查(unchecked)异常。
可以,但是不建议。
不要在 finally 语句块中使用 return! 当 try 语句和 finally 语句中都有 return 语句时,try 语句块中的 return 语句会被忽略。
public static int f(int value) {try {return value * value;} finally {if (value == 2) {return 0;}}}public static void main(String[] args) {System.out.println(f(2)); // 0}
不一定的!在某些情况下,finally 中的代码不会被执行。
就比如说 finally 之前虚拟机被终止运行的话,finally 中的代码就不会被执行。
try {System.out.println("Try to do something");throw new RuntimeException("RuntimeException");} catch (Exception e) {System.out.println("Catch Exception -> " + e.getMessage());// 终止当前正在运行的Java虚拟机System.exit(1);} finally {System.out.println("Finally");}// 输出Try to do somethingCatch Exception -> RuntimeException
https://javaguide.cn/java/basis/java-basic-questions-03.html#%E5%BC%82%E5%B8%B8
