Isn't an unchecked exception that is caught in a try block a checked exception in Java?

后端 未结 3 1755
执笔经年
执笔经年 2021-02-08 23:05

I was told that in Java, unchecked exceptions can be caught in a try block, but if it\'s caught, isn\'t it called a checked exception?

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-08 23:43

    No, it's not called a checked exception just because it is caught. A catch block can be written to catch any kind of Exception or Error. Checked exceptions are those that are subject to the Catch or Specify Requirement, meaning that you are required to either catch them or declare that your method may throw them. You can think of the term checked as meaning that the compiler will check to make sure you adhere to the catch or specify requirement. Errors and RuntimeExceptions are called unchecked exceptions because the compiler does not enforce this requirement on them.

提交回复
热议问题