<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"	>
<channel>
	<title>Comments on: Evil Behavior with Unchecked Checked Exceptions</title>
	<atom:link href="http://johannesbrodwall.com/2007/07/17/evil-behavior-with-unchecked-checked-exceptions/feed/" rel="self" type="application/rss+xml" />
	<link>http://johannesbrodwall.com/2007/07/17/evil-behavior-with-unchecked-checked-exceptions/</link>
	<description>Johannes Brodwall&#039;s Musings on Software Architecture and Programming</description>
	<lastBuildDate>Fri, 13 Apr 2012 19:13:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Johannes Brodwall</title>
		<link>http://johannesbrodwall.com/2007/07/17/evil-behavior-with-unchecked-checked-exceptions/comment-page-1/#comment-9037</link>
		<dc:creator>Johannes Brodwall</dc:creator>
		<pubDate>Thu, 19 Jul 2007 22:51:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.brodwall.com/johannes/blog/2007/07/17/evil-behavior-with-unchecked-checked-exceptions/#comment-9037</guid>
		<description>Hi, Harald

The code as it stands doesn&#039;t work. I expect the template code was eaten by the HTML-izer of both my blog and/or crazy bob&#039;s blog. Here is the correct code:

&lt;pre&gt;&lt;code&gt;
    public static void throwIt2(final Throwable exception) {
        class Thrower&lt;T extends Throwable&gt; {
            private void sneakyThrow(Throwable exception) throws T {
                throw (T)exception;
            }
        }
        new Thrower&lt;RuntimeException&gt;().sneakyThrow(exception);
    }
&lt;/pre&gt;&lt;/code&gt;

I don&#039;t even get a compiler warning. This is a very neat trick.</description>
		<content:encoded><![CDATA[<p>Hi, Harald</p>
<p>The code as it stands doesn&#8217;t work. I expect the template code was eaten by the HTML-izer of both my blog and/or crazy bob&#8217;s blog. Here is the correct code:</p>
<pre><code>
    public static void throwIt2(final Throwable exception) {
        class Thrower&lt;T extends Throwable&gt; {
            private void sneakyThrow(Throwable exception) throws T {
                throw (T)exception;
            }
        }
        new Thrower&lt;RuntimeException&gt;().sneakyThrow(exception);
    }
</code></pre>
<p>I don't even get a compiler warning. This is a very neat trick.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Johannes Brodwall</title>
		<link>http://johannesbrodwall.com/2007/07/17/evil-behavior-with-unchecked-checked-exceptions/comment-page-1/#comment-84493</link>
		<dc:creator>Johannes Brodwall</dc:creator>
		<pubDate>Thu, 19 Jul 2007 20:51:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.brodwall.com/johannes/blog/2007/07/17/evil-behavior-with-unchecked-checked-exceptions/#comment-84493</guid>
		<description>Hi, Harald&lt;br&gt;&lt;br&gt;The code as it stands doesn&#039;t work. I expect the template code was eaten by the HTML-izer of both my blog and/or crazy bob&#039;s blog. Here is the correct code:&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;code&gt;&lt;br&gt;    public static void throwIt2(final Throwable exception) {&lt;br&gt;        class Thrower&lt;T extends Throwable&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&lt;RuntimeException&gt;().sneakyThrow(exception);&lt;br&gt;    }&lt;br&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;I don&#039;t even get a compiler warning. This is a very neat trick.</description>
		<content:encoded><![CDATA[<p>Hi, Harald</p>
<p>The code as it stands doesn&#39;t work. I expect the template code was eaten by the HTML-izer of both my blog and/or crazy bob&#39;s blog. Here is the correct code:</p>
<p>&lt;pre&gt;<code><br />    public static void throwIt2(final Throwable exception) {<br />        class Thrower&lt;T extends Throwable&gt; {<br />            private void sneakyThrow(Throwable exception) throws T {<br />                throw (T)exception;<br />            }<br />        }<br />        new Thrower&lt;RuntimeException&gt;().sneakyThrow(exception);<br />    }<br /></code>&lt;/pre&gt;</p>
<p>I don&#39;t even get a compiler warning. This is a very neat trick.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: .k</title>
		<link>http://johannesbrodwall.com/2007/07/17/evil-behavior-with-unchecked-checked-exceptions/comment-page-1/#comment-8858</link>
		<dc:creator>.k</dc:creator>
		<pubDate>Tue, 17 Jul 2007 23:33:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.brodwall.com/johannes/blog/2007/07/17/evil-behavior-with-unchecked-checked-exceptions/#comment-8858</guid>
		<description>It can actually be a lot easier than Anders&#039; example. See this http://weblogs.java.net/blog/crazybob/archive/2004/09/dont_try_this_a.html
for even more clever implementations. :-)

I propose a utility-class with something like this, and we&#039;re good to go: 

  public static void throwUnchecked(final Throwable pException) {
    // Type parameter to Thrower is erased at compile-time
    new Thrower().sneakyThrow(pException);
  }

  private static class Thrower {
    private void sneakyThrow(Throwable pException) throws T {
      throw (T) pException; // Unchecked cast
    }
  }

I&#039;m starting to think this might be useful.. Or... Maybe I&#039;m just tired.. :-P


.k</description>
		<content:encoded><![CDATA[<p>It can actually be a lot easier than Anders&#8217; example. See this <a href="http://weblogs.java.net/blog/crazybob/archive/2004/09/dont_try_this_a.html" rel="nofollow">http://weblogs.java.net/blog/crazybob/archive/2004/09/dont_try_this_a.html</a><br />
for even more clever implementations. :-)</p>
<p>I propose a utility-class with something like this, and we&#8217;re good to go: </p>
<p>  public static void throwUnchecked(final Throwable pException) {<br />
    // Type parameter to Thrower is erased at compile-time<br />
    new Thrower().sneakyThrow(pException);<br />
  }</p>
<p>  private static class Thrower {<br />
    private void sneakyThrow(Throwable pException) throws T {<br />
      throw (T) pException; // Unchecked cast<br />
    }<br />
  }</p>
<p>I&#8217;m starting to think this might be useful.. Or&#8230; Maybe I&#8217;m just tired.. :-P</p>
<p>.k</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: .k</title>
		<link>http://johannesbrodwall.com/2007/07/17/evil-behavior-with-unchecked-checked-exceptions/comment-page-1/#comment-84492</link>
		<dc:creator>.k</dc:creator>
		<pubDate>Tue, 17 Jul 2007 21:33:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.brodwall.com/johannes/blog/2007/07/17/evil-behavior-with-unchecked-checked-exceptions/#comment-84492</guid>
		<description>It can actually be a lot easier than Anders&#039; example. See this &lt;a href=&quot;http://weblogs.java.net/blog/crazybob/archive/2004/09/dont_try_this_a.html&quot;&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&#039;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&#039;m starting to think this might be useful.. Or... Maybe I&#039;m just tired.. :-P&lt;br&gt;&lt;br&gt;&lt;br&gt;.k</description>
		<content:encoded><![CDATA[<p>It can actually be a lot easier than Anders&#39; example. See this <a href="http://weblogs.java.net/blog/crazybob/archive/2004/09/dont_try_this_a.html">http://weblogs.java.net/blog/crazybob/archive/2&#8230;</a><br />for even more clever implementations. :-)</p>
<p>I propose a utility-class with something like this, and we&#39;re good to go: </p>
<p>  public static void throwUnchecked(final Throwable pException) {<br />    // Type parameter to Thrower is erased at compile-time<br />    new Thrower().sneakyThrow(pException);<br />  }</p>
<p>  private static class Thrower {<br />    private void sneakyThrow(Throwable pException) throws T {<br />      throw (T) pException; // Unchecked cast<br />    }<br />  }</p>
<p>I&#39;m starting to think this might be useful.. Or&#8230; Maybe I&#39;m just tired.. :-P</p>
<p>.k</p>
]]></content:encoded>
	</item>
</channel>
</rss>

