Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #6766
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!goblin3!goblin.stu.neva.ru!newsfeed3.funet.fi!newsfeeds.funet.fi!feeder2.news.elisa.fi!fi.sn.net!newsfeed2.tdcnet.fi!news.song.fi!not-for-mail |
|---|---|
| From | Jukka Lahtinen <jtfjdehf@hotmail.com.invalid> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Catching mulitple Exceptions in JDK 1.7 |
| Organization | none |
| References | <ivm537l6o5sq61oo6cigbrkb4ti8ujmibf@4ax.com> <m362miriv4.fsf@despammed.com> <0510e90d-1a19-4fe1-9445-65314b5da038@glegroupsg2000goo.googlegroups.com> <p00g379lejgiq3c2goiejo20dbcm7fu7ci@4ax.com> |
| Content-Type | text/plain;charset="iso-8859-1" |
| Content-Transfer-Encoding | 8bit |
| Date | Wed, 03 Aug 2011 00:11:07 +0300 |
| Message-ID | <m3vcufh638.fsf@despammed.com> (permalink) |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) |
| Cancel-Lock | sha1:X4zR8KFBxPjmuoBCb/2sBEG4smA= |
| MIME-Version | 1.0 |
| Lines | 46 |
| NNTP-Posting-Host | 81.17.207.67 |
| X-Trace | 1312319471 news.tdc.fi 4371 81.17.207.67:43510 |
| X-Complaints-To | abuse@tdcnet.fi |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:6766 |
Show key headers only | View raw
Roedy Green <see_website@mindprod.com.invalid> writes:
> On Mon, 1 Aug 2011 23:54:34 -0700 (PDT), Lew <lewbloch@gmail.com>
> wrote, quoted or indirectly quoted someone who said :
>>In fact, if you only want to handle the IOException-ness of the exception, =
>>you wouldn't even bother mentioning 'SQLException' at all. You'd just 'cat=
>>ch(IOException...)'. =20
> Here is a better example to illustrate my question:
> catch (IllegalArgumentException|IOException ex)
I think we understood your original question.
> What is the compile-time type of ex?
..
> What is the run-time type of ex if you got an IOException ?
..
> Or is there a rule that catch (a | b ex ) requires a to be a subclass
> of b, which would neatly sidestep the problem, but then the feature
> would not do anything useful.
That restriction wouldn't make any sense. If a extends b, there's no
point in catch (a|b) since you could do exactly the same with just
catch (b).
I haven't studied how it is handled, but I *suppose* the compile-time
type is the most specific Throwable that both a and b are subtype of
(probably in most cases Exception or some subclass of it). But of course
it wouldn't catch other subtypes that aren't either a or b or some
subtype of one of them.
And at runtime the JVM should know the exact type and you should be able
to ask it with instanceof like anywhere else, like I suggested in my
earlier followup.
if (ex instanceof Foo) {
Foo bar = (Foo) ex;
...
}
But if you need to do that, you should't catch multiple types with
the same catch.
--
Jukka Lahtinen
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar
Catching mulitple Exceptions in JDK 1.7 Roedy Green <see_website@mindprod.com.invalid> - 2011-07-29 09:14 -0700
Re: Catching mulitple Exceptions in JDK 1.7 Roedy Green <see_website@mindprod.com.invalid> - 2011-07-29 09:18 -0700
Re: Catching mulitple Exceptions in JDK 1.7 markspace <-@.> - 2011-07-29 09:28 -0700
Re: Catching mulitple Exceptions in JDK 1.7 Jukka Lahtinen <jtfjdehf@hotmail.com.invalid> - 2011-07-31 10:48 +0300
Re: Catching mulitple Exceptions in JDK 1.7 Lew <lewbloch@gmail.com> - 2011-08-01 23:54 -0700
Re: Catching mulitple Exceptions in JDK 1.7 Roedy Green <see_website@mindprod.com.invalid> - 2011-08-02 06:56 -0700
Re: Catching mulitple Exceptions in JDK 1.7 Patricia Shanahan <pats@acm.org> - 2011-08-02 14:07 -0700
Re: Catching mulitple Exceptions in JDK 1.7 supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-08-03 23:31 -0400
Re: Catching mulitple Exceptions in JDK 1.7 Patricia Shanahan <pats@acm.org> - 2011-08-03 21:03 -0700
Re: Catching mulitple Exceptions in JDK 1.7 Jeff Higgins <jeff@invalid.invalid> - 2011-08-05 19:02 -0400
Re: Catching mulitple Exceptions in JDK 1.7 Patricia Shanahan <pats@acm.org> - 2011-08-06 09:45 -0700
Re: Catching mulitple Exceptions in JDK 1.7 Jukka Lahtinen <jtfjdehf@hotmail.com.invalid> - 2011-08-03 00:11 +0300
csiph-web