Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail From: Jan Burse Newsgroups: comp.lang.java.programmer Subject: Thumbs up for suppressable exceptions in JDK 1.7 Date: Tue, 27 Sep 2011 09:31:03 +0200 Organization: albasani.net Lines: 57 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.albasani.net S94pB93fP14dCss5T4N6ZNb8Yn3n+9KcsugX1pN2CfaLNVbsO28qVMcA9pWS+jiFOxNHUJbYFVbVvOrFgKxaOv7+d18rbsL3wFQumILOToTqeLE5NWRDjUZ4KIiNTv5C NNTP-Posting-Date: Tue, 27 Sep 2011 07:31:04 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="B2cnTqIit31Pwe0W8i2e4SpFQyPO4yyUqOeqeDRdhhLWKyBraX1qAYWfAnWX9vucH33647/573wVpUyMjSmXvBO6uMBCjd2SIJ93wNQdYwoxmtdxZsyZCUErLkWX+kU0"; mail-complaints-to="abuse@albasani.net" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20110902 Firefox/6.0.2 SeaMonkey/2.3.3 Cancel-Lock: sha1:DCwFCkl99qqcIQ3pWXycyhgUx94= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:8357 Dear All Was just playing around with suppressable exceptions in JDK 1.7. This looks like a great improvement for bug hunting! Best Regards Manually Suppressed: ------------------ public class TestSuppressed { public static void main(String[] args) throws Exception { try { throw new IllegalArgumentException("x"); } catch (IllegalArgumentException x) { x.addSuppressed(new IllegalArgumentException("y")); throw x; } } } gives: Exception in thread "main" java.lang.IllegalArgumentException: x at TestSuppressed.main(TestSuppressed.java:12) Suppressed: java.lang.IllegalArgumentException: y at TestSuppressed.main(TestSuppressed.java:14) ... 5 more Automatically Suppressed: --------------------- public class TestSuppressed implements AutoCloseable { public static void main(String[] args) throws Exception { try (TestSuppressed ts=new TestSuppressed()) { throw new IllegalArgumentException("x"); } } public void close() throws Exception { throw new IllegalArgumentException("y"); } } gives: Exception in thread "main" java.lang.IllegalArgumentException: x at TestSuppressed.main(TestSuppressed.java:9) Suppressed: java.lang.IllegalArgumentException: y at TestSuppressed.close(TestSuppressed.java:20) at TestSuppressed.main(TestSuppressed.java:10) ... 5 more