Why catch Exceptions in Java, when you can catch Throwables?

前端 未结 14 751
一整个雨季
一整个雨季 2020-11-27 13:44

We recently had a problem with a Java server application where the application was throwing Errors which were not caught because Error is a separate subclass of Throwable an

14条回答
  •  渐次进展
    2020-11-27 14:37

    From the Java API documentation:

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

    An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch.

    Errors usually are low-level (eg., raised by the virtual machine) and should not be caught by the application since reasonable continuation might not be possible.

提交回复
热议问题