What is a suppressed exception?

后端 未结 8 1751
借酒劲吻你
借酒劲吻你 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

    You can suppress Exceptions in Java 6 as well (a little trickery involved),

    I created a utility that transparently handles suppressing exception in Java 1.6 and Java 1.7. You can find the implementation here

    All you need is to call:

    public static  T suppress(final T t, final Throwable suppressed) 
    

    to supress a exception, and

    public static Throwable [] getSuppressed(final Throwable t) {
    

    to get the suppressed exceptions of a Exception, in case anybody still uses Java 1.6

提交回复
热议问题