Files
logseq-1/journals/2024_06_28.md

6 lines
1005 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
- [Exception 和 Error 有什么区别?](https://javaguide.cn/java/basis/java-basic-questions-03.html#exception-%E5%92%8C-error-%E6%9C%89%E4%BB%80%E4%B9%88%E5%8C%BA%E5%88%AB) #card #java
id:: 667e7553-cb20-45d8-935e-39dfa35eb667
- 在 Java 中,所有的异常都有一个共同的祖先 `java.lang` 包中的 `Throwable` 类。`Throwable` 类有两个重要的子类:
- **`Exception`** : 程序本身可以处理的异常,可以通过 `catch` 来进行捕获。`Exception` 又可以分为 Checked Exception (受检查异常,必须处理) 和 Unchecked Exception (不受检查异常,可以不处理)。
- **`Error`**`Error` 属于程序无法处理的错误 ~~我们没办法通过 `catch` 来进行捕获~~不建议通过 `catch` 捕获 。例如 Java 虚拟机运行错误(`Virtual MachineError`)、虚拟机内存不够错误 (`OutOfMemoryError`)、类定义错误(`NoClassDefFoundError`)等 。这些异常发生时Java 虚拟机JVM一般会选择线程终止。
-