Path: csiph.com!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Jim Janney Newsgroups: comp.lang.java.programmer Subject: Re: can't throw Date: Wed, 12 Sep 2012 11:27:13 -0600 Organization: Behind the screen, Lady Cai overhears a secret Lines: 52 Message-ID: References: <19af6b94-7a1e-4491-afb2-79782406f560@googlegroups.com> <504fe3a6$0$293$14726298@news.sunsite.dk> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Injection-Info: mx04.eternal-september.org; posting-host="75975abe3fe3503ca7350803ab98e478"; logging-data="8281"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/cGhsA8kzxQo8olctUL/IY" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) Cancel-Lock: sha1:h/3ITxPKaarVqje4eJ6Qs69wHK4= sha1:LyvtELL4qoJSqDrGsGynBoulEs8= Xref: csiph.com comp.lang.java.programmer:18682 Peter Duniho writes: > On Tue, 11 Sep 2012 21:21:38 -0400, Arne Vajhøj wrote: > >> [...] >> But given that languages invented after Java chose not to >> implement checked exceptions, then we must conclude that >> it has not caught on. >> >> (primarily thinking of C# and Scala here) >> >> So the benefits are not that obvious to everyone. > > And more to the point, those other languages do not seem to suffer greatly, > if at all, from the lack of checked exceptions. > > For whatever reason, I've never found checked exceptions a compelling > feature. It's absolutely in the right spirit, one which I agree > wholeheartedly with. And yet I find that at least in the Java > implementation, it seems to create more headaches than it prevents. > > I realize I'm in the minority here. But it's a viewpoint I feel needs to > be expressed. > The major problem I had with checked exceptions was fixed in Java 1.4, when they introduced a standard way to wrap exceptions without losing the original stack trace. Java 7 lets you handle all the bogus exceptions in a single catch clause, so there's a minor nuisance gone. And if you really need it, there's always public static void throwChecked(final Exception e) { class Thrower { public Thrower() throws Exception { throw e; } } try { Thrower.class.newInstance(); } catch (InstantiationException e1) { throw new RuntimeException(e1); // bogus exception: cannot happen } catch (IllegalAccessException e1) { throw new RuntimeException(e1); // bogus exception: cannot happen } } Not that I recommend doing this, but it *is* possible... -- Jim Janney