Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #18790
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail |
|---|---|
| From | Robert Klemme <shortcutter@googlemail.com> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: can't throw |
| Date | Sun, 16 Sep 2012 15:46:44 +0200 |
| Lines | 67 |
| Message-ID | <abm3i5Ffm3dU1@mid.individual.net> (permalink) |
| References | <19af6b94-7a1e-4491-afb2-79782406f560@googlegroups.com> <k2o8sm$ve3$1@dont-email.me> <fea53dab-0659-4f9f-af44-c181c4508aa1@googlegroups.com> <504fe3a6$0$293$14726298@news.sunsite.dk> <JfidnSXpZ8hSLc7NnZ2dnUVZ7oydnZ2d@giganews.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | individual.net yAXZ5efA0mqN14tV5UnunQQLWZs3h900RzdafteQcqB2487y+SzN22tTh7CubPocE= |
| Cancel-Lock | sha1:jeTVBTswyS4ONjZhhqwwLW3tMTA= |
| User-Agent | Mozilla/5.0 (X11; Linux i686; rv:15.0) Gecko/20120827 Thunderbird/15.0 |
| In-Reply-To | <JfidnSXpZ8hSLc7NnZ2dnUVZ7oydnZ2d@giganews.com> |
| Xref | csiph.com comp.lang.java.programmer:18790 |
Show key headers only | View raw
On 09/15/2012 12:33 AM, Leif Roar Moldskred wrote:
> Personally, I think it was a design flaw to tie the checked /
> unchecked to the class hierarchy. An exception's class corresponds to
> a particular error type, but the severity of a particular type of
> error, and wheter we can expect the client to be able to recover from
> it or not, depends on the context.
>
> The choice of checked / unchecked should be made statically _at the
> point of the throw statement_,
Let's see what the consequences of this would be:
1. we need new syntax (e.g. a new keyword), in order to make that
distinction. So it's either
throw checked new IllegalStateException("You can't do that right now.")
throw_checked new IllegalStateException("You can't do that right now.")
2. The complier needs to enforce all exceptions thrown with "throw
checked" are declared in the throws clause.
OK so far, no issues there.
3. Now, assume we have a section of code which throws the same exception
type checked and unchecked. That section is embedded in a try block.
Now we have a catch clause for this exception type attached to the try
block. This prompts the question: which of the thrown exceptions does
the catch block handle - only the checked throws or also unchecked throws?
3a. It handles both. This leads to the unsatisfactory situation where
the same catch block needs to handle programmer errors (now
RuntimeException and subclasses) and other errors which are actually
expected. That's not good since programmer errors (and catastrophic
situations like OOM are usually handled quite close to Thread.run, i.e.
further up the call stack.
3b. The programmer can decide, so we need a new syntax again:
catch checked ( IllegalStateException e )
This will only catch checked exceptions. Do we now need an additional
syntax for "unchecked", e.g.
catch unchecked ( IllegalStateException e )
And what do we do if we want to cover both cases (e.g. because we just
want to print the error)? Do we then do this?
catch checked, unchecked ( IllegalStateException e )
Or do we use the current form to mean "catch both"?
catch ( IllegalStateException e )
In which way we resolve these questions it's obvious that one can easily
forget a keyword or make a different error so one ends handling other
exceptions than intended.
Given the fact that the type of exception also describes the type of
error and that in turn is related to the classification "programmer
error" / "no programmer error" I am not so sure whether the additional
complication your distinction at call site introduces is actually
worthwhile.
Kind regards
robert
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
can't throw bob smith <bob@coolfone.comze.com> - 2012-09-11 13:16 -0700
Re: can't throw markspace <-@.> - 2012-09-11 13:34 -0700
Re: can't throw Lew <lewbloch@gmail.com> - 2012-09-11 14:15 -0700
Re: can't throw Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-09-11 17:02 -0400
Re: can't throw Lew <lewbloch@gmail.com> - 2012-09-11 14:17 -0700
Re: can't throw Arne Vajhøj <arne@vajhoej.dk> - 2012-09-11 21:21 -0400
Re: can't throw Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2012-09-11 21:59 -0700
Re: can't throw Gene Wirchenko <genew@ocis.net> - 2012-09-12 09:18 -0700
Re: can't throw Robert Klemme <shortcutter@googlemail.com> - 2012-09-12 19:09 +0200
Re: can't throw markspace <-@.> - 2012-09-12 10:56 -0700
Re: can't throw Arne Vajhøj <arne@vajhoej.dk> - 2012-09-12 18:36 -0400
Re: can't throw Gene Wirchenko <genew@ocis.net> - 2012-09-12 18:29 -0700
Re: can't throw Patricia Shanahan <pats@acm.org> - 2012-09-12 18:34 -0700
Re: can't throw Arne Vajhøj <arne@vajhoej.dk> - 2012-09-12 21:37 -0400
Re: can't throw Arne Vajhøj <arne@vajhoej.dk> - 2012-09-12 21:54 -0400
Re: can't throw Jim Janney <jjanney@shell.xmission.com> - 2012-09-12 11:27 -0600
Re: can't throw Arne Vajhøj <arne@vajhoej.dk> - 2012-09-12 18:24 -0400
Re: can't throw Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2012-09-13 22:20 -0700
Re: can't throw Gene Wirchenko <genew@ocis.net> - 2012-09-14 09:49 -0700
Re: can't throw Robert Klemme <shortcutter@googlemail.com> - 2012-09-14 20:50 +0200
Re: can't throw Lew <lewbloch@gmail.com> - 2012-09-14 13:02 -0700
Re: can't throw Gene Wirchenko <genew@ocis.net> - 2012-09-14 14:06 -0700
Re: can't throw Gene Wirchenko <genew@ocis.net> - 2012-09-14 13:16 -0700
Re: can't throw Robert Klemme <shortcutter@googlemail.com> - 2012-09-14 23:07 +0200
Re: can't throw Lew <lewbloch@gmail.com> - 2012-09-14 14:28 -0700
Re: can't throw Gene Wirchenko <genew@ocis.net> - 2012-09-16 20:04 -0700
Re: can't throw Arne Vajhøj <arne@vajhoej.dk> - 2012-09-12 18:16 -0400
Re: can't throw Lew <lewbloch@gmail.com> - 2012-09-12 23:15 -0700
Re: can't throw Leif Roar Moldskred <leifm@dimnakorr.com> - 2012-09-14 17:33 -0500
Re: can't throw Robert Klemme <shortcutter@googlemail.com> - 2012-09-16 15:46 +0200
Re: can't throw Leif Roar Moldskred <leifm@dimnakorr.com> - 2012-09-16 12:17 -0500
Re: can't throw Robert Klemme <shortcutter@googlemail.com> - 2012-09-16 22:36 +0200
Re: can't throw Gene Wirchenko <genew@ocis.net> - 2012-09-16 20:07 -0700
Re: can't throw Robert Klemme <shortcutter@googlemail.com> - 2012-09-17 07:41 +0200
Re: can't throw Gene Wirchenko <genew@ocis.net> - 2012-09-17 09:51 -0700
Re: can't throw Robert Klemme <shortcutter@googlemail.com> - 2012-09-17 21:00 +0200
Re: can't throw Gene Wirchenko <genew@ocis.net> - 2012-09-17 13:23 -0700
Re: can't throw Joerg Meier <joergmmeier@arcor.de> - 2012-09-17 18:52 +0200
Re: can't throw Lew <lewbloch@gmail.com> - 2012-09-17 11:22 -0700
Re: can't throw Leif Roar Moldskred <leifm@dimnakorr.com> - 2012-09-17 02:52 -0500
Re: can't throw Leif Roar Moldskred <leifm@dimnakorr.com> - 2012-09-17 02:39 -0500
Re: can't throw Robert Klemme <shortcutter@googlemail.com> - 2012-09-17 21:02 +0200
Re: can't throw markspace <-@.> - 2012-09-11 14:28 -0700
Re: can't throw Arne Vajhøj <arne@vajhoej.dk> - 2012-09-11 21:14 -0400
Re: can't throw Arne Vajhøj <arne@vajhoej.dk> - 2012-09-12 18:11 -0400
Re: can't throw Robert Klemme <shortcutter@googlemail.com> - 2012-09-12 08:31 +0200
Re: can't throw bob smith <bob@coolfone.comze.com> - 2012-09-12 11:40 -0700
Re: can't throw Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-09-12 15:50 -0400
Re: can't throw Lew <lewbloch@gmail.com> - 2012-09-12 12:52 -0700
Re: can't throw Robert Klemme <shortcutter@googlemail.com> - 2012-09-12 23:24 +0200
Re: can't throw Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-09-12 15:10 -0700
Re: can't throw Robert Klemme <shortcutter@googlemail.com> - 2012-09-13 23:32 +0200
Re: can't throw Arne Vajhøj <arne@vajhoej.dk> - 2012-09-12 18:06 -0400
Re: can't throw Roedy Green <see_website@mindprod.com.invalid> - 2012-09-12 20:55 -0700
csiph-web