Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #7048
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nx02.iad01.newshosting.com!newshosting.com!news-out.readnews.com!transit3.readnews.com!postnews.google.com!m5g2000prh.googlegroups.com!not-for-mail |
|---|---|
| From | KevinSimonson <kvnsmnsn@hotmail.com> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Trying to Understand Purpose of a Catch Block for IOException in the Presence of One for FileNotFound |
| Date | Fri, 12 Aug 2011 08:39:48 -0700 (PDT) |
| Organization | http://groups.google.com |
| Lines | 32 |
| Message-ID | <0f7fb5c4-6031-4778-9ef7-de757bbdda39@m5g2000prh.googlegroups.com> (permalink) |
| NNTP-Posting-Host | 216.49.181.254 |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| X-Trace | posting.google.com 1313163588 28395 127.0.0.1 (12 Aug 2011 15:39:48 GMT) |
| X-Complaints-To | groups-abuse@google.com |
| NNTP-Posting-Date | Fri, 12 Aug 2011 15:39:48 +0000 (UTC) |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | m5g2000prh.googlegroups.com; posting-host=216.49.181.254; posting-account=gsXmKQkAAADuyNfZpkeBrCCcqQvlDvn9 |
| User-Agent | G2/1.0 |
| X-Google-Web-Client | true |
| X-Google-Header-Order | ARLUEHNKC |
| X-HTTP-UserAgent | Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET CLR 1.1.4322; InfoPath.2; .NET4.0E; .NET4.0C),gzip(gfe) |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:7048 |
Show key headers only | View raw
If I write a piece of code that constructs an object of class <PrintWriter> by passing it an object of class <BufferedWriter>, constructed by passing _it_ an object of type <FileWriter> (all three classes under <java.io>), don't have a <throws> clause, have only a <catch> clause for <FileNotFoundException>, and then try to compile the code the compiler complains, telling me, "unreported exception java.io.IOException java.io.IOException: must be caught or declared to be thrown". Of course, if I put a <catch> clause there for <IOException>, that fixes the problem and the program compiles just fine. If, on the other hand, I write a piece of code that constructs an object of class <Scanner>, constructed by passing it an object of type <File>, don't have a <throws> clause for <FileNotFoundException>, and don't put the constructor call in a <try> block at all, I get a similar complaint about me not saying anything about exception <FileNotFound>. Finally, if I have some code that has constructors for _both <PrintWriter> and_ <Scanner>, I have to have a <catch> clause for _both <IOException> and_ <FileNotFoundException>, in order to keep the compiler happy. But in such a situation I have not been able to find a way to _actually get <IOException> thrown_! What is the purpose of having a <catch> block for <IOException> if nothing I do with my code will actually throw an <IOException> that is not a <FileNotFoundException>? Or, alternately, is there something I can do to _get_ an <IOException> that is not a <FileNotFoundException> thrown? I would appreciate any information anyone can give me on this. Kevin Simonson
Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar
Trying to Understand Purpose of a Catch Block for IOException in the Presence of One for FileNotFound KevinSimonson <kvnsmnsn@hotmail.com> - 2011-08-12 08:39 -0700
Re: Trying to Understand Purpose of a Catch Block for IOException in the Presence of One for FileNotFound Knute Johnson <september@knutejohnson.com> - 2011-08-12 08:54 -0700
Re: Trying to Understand Purpose of a Catch Block for IOException in the Presence of One for FileNotFound markspace <-@.> - 2011-08-12 08:57 -0700
Re: Trying to Understand Purpose of a Catch Block for IOException in the Presence of One for FileNotFound KevinSimonson <kvnsmnsn@hotmail.com> - 2011-08-12 11:19 -0700
Re: Trying to Understand Purpose of a Catch Block for IOException in the Presence of One for FileNotFound markspace <-@.> - 2011-08-12 12:08 -0700
Re: Trying to Understand Purpose of a Catch Block for IOException in the Presence of One for FileNotFound Patricia Shanahan <pats@acm.org> - 2011-08-12 12:26 -0700
Re: Trying to Understand Purpose of a Catch Block for IOException in the Presence of One for FileNotFound Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-12 19:35 +0000
Re: Trying to Understand Purpose of a Catch Block for IOException in the Presence of One for FileNotFound Patricia Shanahan <pats@acm.org> - 2011-08-12 12:31 -0700
Re: Trying to Understand Purpose of a Catch Block for IOException in the Presence of One for FileNotFound KevinSimonson <kvnsmnsn@hotmail.com> - 2011-08-12 13:10 -0700
Re: Trying to Understand Purpose of a Catch Block for IOException in the Presence of One for FileNotFound Lew <lewbloch@gmail.com> - 2011-08-12 14:27 -0700
csiph-web