<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Thinking inside a bigger box - Latest Comments in Evil Behavior with Unchecked Checked Exceptions</title><link>http://thinkinginsideabiggerbox.disqus.com/</link><description></description><atom:link href="https://thinkinginsideabiggerbox.disqus.com/evil_behavior_with_unchecked_checked_exceptions/latest.rss" rel="self"></atom:link><language>en</language><lastBuildDate>Thu, 19 Jul 2007 18:51:58 -0000</lastBuildDate><item><title>Re: Evil Behavior with Unchecked Checked Exceptions</title><link>http://johannesbrodwall.com/2007/07/17/evil-behavior-with-unchecked-checked-exceptions/#comment-1798430</link><description>&lt;p&gt;Hi, Harald&lt;/p&gt;&lt;p&gt;The code as it stands doesn't work. I expect the template code was eaten by the HTML-izer of both my blog and/or crazy bob's blog. Here is the correct code:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;pre&gt;&lt;code&gt;&lt;br&gt;    public static void throwIt2(final Throwable exception) {&lt;br&gt;        class Thrower&amp;lt;T extends Throwable&amp;gt; {&lt;br&gt;            private void sneakyThrow(Throwable exception) throws T {&lt;br&gt;                throw (T)exception;&lt;br&gt;            }&lt;br&gt;        }&lt;br&gt;        new Thrower&amp;lt;RuntimeException&amp;gt;().sneakyThrow(exception);&lt;br&gt;    }&lt;br&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;I don't even get a compiler warning. This is a very neat trick.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Johannes Brodwall</dc:creator><pubDate>Thu, 19 Jul 2007 18:51:58 -0000</pubDate></item><item><title>Re: Evil Behavior with Unchecked Checked Exceptions</title><link>http://johannesbrodwall.com/2007/07/17/evil-behavior-with-unchecked-checked-exceptions/#comment-1798431</link><description>&lt;p&gt;It can actually be a lot easier than Anders' example. See this &lt;a href="http://weblogs.java.net/blog/crazybob/archive/2004/09/dont_try_this_a.html" rel="nofollow noopener" target="_blank" title="http://weblogs.java.net/blog/crazybob/archive/2004/09/dont_try_this_a.html"&gt;http://weblogs.java.net/blo...&lt;/a&gt;&lt;br&gt;for even more clever implementations. :-)&lt;/p&gt;&lt;p&gt;I propose a utility-class with something like this, and we're good to go:&lt;/p&gt;&lt;p&gt;  public static void throwUnchecked(final Throwable pException) {&lt;br&gt;    // Type parameter to Thrower is erased at compile-time&lt;br&gt;    new Thrower().sneakyThrow(pException);&lt;br&gt;  }&lt;/p&gt;&lt;p&gt;  private static class Thrower {&lt;br&gt;    private void sneakyThrow(Throwable pException) throws T {&lt;br&gt;      throw (T) pException; // Unchecked cast&lt;br&gt;    }&lt;br&gt;  }&lt;/p&gt;&lt;p&gt;I'm starting to think this might be useful.. Or... Maybe I'm just tired.. :-P&lt;/p&gt;&lt;p&gt;.k&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">.k</dc:creator><pubDate>Tue, 17 Jul 2007 19:33:47 -0000</pubDate></item></channel></rss>