Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #637
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail |
|---|---|
| NNTP-Posting-Date | Sun, 24 Apr 2011 08:53:15 -0500 |
| Date | Sun, 24 Apr 2011 06:53:11 -0700 |
| From | Patricia Shanahan <pats@acm.org> |
| User-Agent | Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 |
| MIME-Version | 1.0 |
| 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> <87ei4sm7b6.fsf@merciadriluca-station.MERCIADRILUCA> |
| In-Reply-To | <87ei4sm7b6.fsf@merciadriluca-station.MERCIADRILUCA> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Message-ID | <_q6dnZ2mCMrWtinQnZ2dnUVZ_vOdnZ2d@earthlink.com> (permalink) |
| Lines | 48 |
| X-Usenet-Provider | http://www.giganews.com |
| NNTP-Posting-Host | 75.8.126.96 |
| X-Trace | sv3-YDwYx1kCYarWPrWF2r1xVMxSNBH/E8dfRelfKiOANK4inYXeYAyVC3LT1z73Nn9Ayq2xfXzYAUpmH6R!2QGWZQ0+WvBVnlawtb0aXZjyckIvnsFH/tsGMfv+0IDS3+soHJgUAg799x9zS5maHxPSZVfgZymN!p9yx2SioumkSCFbKvHcPZX6rC+Ko1OSFraepPrlSpqw= |
| X-Abuse-and-DMCA-Info | Please be sure to forward a copy of ALL headers |
| X-Abuse-and-DMCA-Info | Otherwise we will be unable to process your complaint properly |
| X-Postfilter | 1.3.40 |
| X-Original-Bytes | 3118 |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.java.help:637 |
Show key headers only | View raw
On 4/24/2011 12:34 AM, Merciadri Luca wrote:
> -----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?
If I understand the question correctly, the difference is which
exception the high level method sees.
I generally design and document the exceptions a method throws along
with designing and documenting its arguments and return. Sometimes it
may make sense to let something like IOException filter up. In other
cases it is better to throw an exception that adds information the
method has, and wraps the IOException as its cause.
Patricia
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