Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #635
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!feeder1.cambriumusenet.nl!feed.tweaknews.nl!87.79.20.105.MISMATCH!news.netcologne.de!ramfeed1.netcologne.de!news.tele.dk!feed118.news.tele.dk!dotsrc.org!filter.dotsrc.org!news.dotsrc.org!not-for-mail |
|---|---|
| Newsgroups | comp.lang.java.help |
| Subject | Re: Some same exceptions used in a given file |
| References | <87r58s28w3.fsf@merciadriluca-station.MERCIADRILUCA> <x-Sdnf9tjIy5pi7QnZ2dnUVZ_vqdnZ2d@earthlink.com> |
| From | Merciadri Luca <Luca.Merciadri@student.ulg.ac.be> |
| Organization | ULg |
| Date | Sun, 24 Apr 2011 09:34:21 +0200 |
| Message-ID | <87ei4sm7b6.fsf@merciadriluca-station.MERCIADRILUCA> (permalink) |
| User-Agent | Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) |
| Cancel-Lock | sha1:ZWbVSydnIMsUUP4zcVQUdWx77yw= |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Lines | 51 |
| NNTP-Posting-Host | 85.26.2.239 |
| X-Trace | news.sunsite.dk DXC=MS;K^7cmeWa]OI4DlPLEfeYSB=nbEKnkk6NDZ77URYDaB`G2cTG;MnaLGVLjEY^2Yh[=LHD=0P^Yd9g\V1BeNHOiDZ4Udfg@BlbP14>oS6[i6`?DnJl7^Pb6o |
| X-Complaints-To | staff@sunsite.dk |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.java.help:635 |
Show key headers only | View raw
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Patricia Shanahan <pats@acm.org> writes:
> On 4/23/2011 10:08 AM, Merciadri Luca wrote:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> Hi,
>>
>> In some of my code files, I've got the following catch block
>>
>> ==
>> catch (IOException cantOpenFile)
>> {
>> System.err.println("Can't open " + inputFilename + ".");
>> System.exit(1);
>> }
>> ==
>> more than once, but at different places in the file. Is it possible to
>> define this somewhere so that I can directly catch the exception with
>> the two given commands? (Just as one would define his own exception.)
>
> I can see two options for reducing the amount of duplicate code:
>
> 1. Put the try-catch for IOException at a high enough level in the call
> hierarchy, and wide enough scope, that it will catch all instances of
> IOException for which you want the same handling.
>
> 2. Extract the handling for IOException into a method that can be called
> from multiple catch blocks.
And what is the difference between try and catch at a high enough
level and the same, but with a throw in the method that might generate
an exception?
- --
Merciadri Luca
See http://www.student.montefiore.ulg.ac.be/~merciadri/
- --
It takes two to tango.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>
iEYEARECAAYFAk2z0n0ACgkQM0LLzLt8MhwLlwCgl71lB3ptskt0TWntW5FxOWX5
0IEAn0Dir37LnMl5Jh6lfevV6tG4WTFq
=v8mI
-----END PGP SIGNATURE-----
Back to comp.lang.java.help | Previous | Next — Previous in thread | Next in thread | Find similar
Some same exceptions used in a given file Merciadri Luca <Luca.Merciadri@student.ulg.ac.be> - 2011-04-23 19:08 +0200
Re: Some same exceptions used in a given file Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-04-23 14:40 -0400
Re: Some same exceptions used in a given file Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-04-23 16:23 -0400
Re: Some same exceptions used in a given file Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-04-23 17:23 -0300
Re: Some same exceptions used in a given file Merciadri Luca <Luca.Merciadri@student.ulg.ac.be> - 2011-04-24 00:00 +0200
Re: Some same exceptions used in a given file Lew <noone@lewscanon.com> - 2011-04-23 18:22 -0400
Re: Some same exceptions used in a given file Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-04-23 18:31 -0400
Re: Some same exceptions used in a given file Merciadri Luca <Luca.Merciadri@student.ulg.ac.be> - 2011-04-24 01:20 +0200
Re: Some same exceptions used in a given file Lew <noone@lewscanon.com> - 2011-04-23 20:19 -0400
Re: Some same exceptions used in a given file Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-04-23 22:25 -0300
Re: Some same exceptions used in a given file Merciadri Luca <Luca.Merciadri@student.ulg.ac.be> - 2011-04-24 09:24 +0200
Re: Some same exceptions used in a given file Patricia Shanahan <pats@acm.org> - 2011-04-23 13:48 -0700
Re: Some same exceptions used in a given file Merciadri Luca <Luca.Merciadri@student.ulg.ac.be> - 2011-04-24 09:34 +0200
Re: Some same exceptions used in a given file Lew <noone@lewscanon.com> - 2011-04-24 09:40 -0400
Re: Some same exceptions used in a given file Patricia Shanahan <pats@acm.org> - 2011-04-24 06:53 -0700
Re: Some same exceptions used in a given file Merciadri Luca <Luca.Merciadri@student.ulg.ac.be> - 2011-04-24 01:28 +0200
csiph-web