<?xml version="1.0" encoding="utf-8"?>
<rss 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><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://www.brodwall.com/johannes/blog/2007/07/17/evil-behavior-with-unchecked-checked-exceptions/#comment-1798430</link><description>Hi, Harald&lt;br&gt;&lt;br&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;br&gt;&lt;br&gt;&amp;lt;pre&amp;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;&amp;lt;/pre&amp;gt;&lt;br&gt;&lt;br&gt;I don't even get a compiler warning. This is a very neat trick.</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://www.brodwall.com/johannes/blog/2007/07/17/evil-behavior-with-unchecked-checked-exceptions/#comment-1798431</link><description>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"&gt;http://weblogs.java.net/blog/crazybob/archive/2...&lt;/a&gt;&lt;br&gt;for even more clever implementations. :-)&lt;br&gt;&lt;br&gt;I propose a utility-class with something like this, and we're good to go: &lt;br&gt;&lt;br&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;br&gt;&lt;br&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;br&gt;&lt;br&gt;I'm starting to think this might be useful.. Or... Maybe I'm just tired.. :-P&lt;br&gt;&lt;br&gt;&lt;br&gt;.k</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>