First of all, you need to know 一切皆是对象,异常当然是一个对象。 接下来要知道异常分为受检查异常和运行时异常(感谢@泊浮目提醒)。 你所说的异常处理机制应该是受检查异常,受检查异常是可以被java的异常处理机制所处理的,因为他们都是实现了Throwablethis interface in java.
catch is a logically correct and complete part. Because the caught exception may affect the next action of your method. For example, when opening a file, you have to make sure the file is open so that you can read and write information. Catching the exception will let you confirm if the file is not opened, why, and what you need to do next. Create a new file? Or just return without reading or writing information?
Finally, if you want to understand the exception handling mechanism, you still need to read 《java编程思想》this magical book.
First of all, you need to know
一切皆是对象
,异常当然是一个对象。接下来要知道异常分为
受检查异常
和运行时异常
(感谢@泊浮目提醒)。你所说的异常处理机制应该是受检查异常,受检查异常是可以被java的异常处理机制所处理的,因为他们都是实现了
Throwable
this interface in java.catch is a logically correct and complete part.
Because the caught exception may affect the next action of your method.
For example, when opening a file, you have to make sure the file is open so that you can read and write information.
Catching the exception will let you confirm if the file is not opened, why, and what you need to do next. Create a new file? Or just return without reading or writing information?
Finally, if you want to understand the exception handling mechanism, you still need to read
《java编程思想》
this magical book.What is said upstairs
不受检查异常
应该叫运行时异常
will be easier to understand. Okay, let’s answer the questions, one by one.Yes.
Of course. Also
finally
is also an important part of the overall logic.Let’s take a look at one of my articles, which explains the anomalies in quite detail.