difference between errors and unchecked exceptions in java?

后端 未结 7 1115
时光取名叫无心
时光取名叫无心 2020-12-16 18:22

As we know if any error or any unchecked exception occurs then our program will halt, then what are the differences between those?

7条回答
  •  没有蜡笔的小新
    2020-12-16 18:59

    From the Error Javadoc:

    An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch. Most such errors are abnormal conditions. The ThreadDeath error, though a "normal" condition, is also a subclass of Error because most applications should not try to catch it.

    Versus the Exception Javadoc

    The class Exception and its subclasses are a form of Throwable that indicates conditions that a reasonable application might want to catch.

    So, even though an unchecked exception is not required to be caught, you may want to. An error, you don't want to catch.

提交回复
热议问题