What is a suppressed exception?

后端 未结 8 1755
借酒劲吻你
借酒劲吻你 2020-11-28 04:51

A comment (by user soc) on an answer to a question about tail call optimisation mentioned that Java 7 has a new feature called \"suppressed exceptions\", because of \"the ad

8条回答
  •  春和景丽
    2020-11-28 05:27

    Suppressed exceptions are additional exceptions that occur within a try-with-resources statement (introduced in Java 7) when AutoCloseable resources are closed. Because multiple exceptions may occur while closing AutoCloseable resources, additional exceptions are attached to a primary exception as suppressed exceptions.

    Looking at the bytecode of a piece of try-with-resources sample code, standard JVM exception handlers are used to accommodate the try-with-resources semantics.

提交回复
热议问题