Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.help > #617

Re: Some same exceptions used in a given file

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 Sat, 23 Apr 2011 15:48:36 -0500
Date Sat, 23 Apr 2011 13:48:31 -0700
From Patricia Shanahan <pats@acm.org>
User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.2; 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>
In-Reply-To <87r58s28w3.fsf@merciadriluca-station.MERCIADRILUCA>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Message-ID <x-Sdnf9tjIy5pi7QnZ2dnUVZ_vqdnZ2d@earthlink.com> (permalink)
Lines 32
X-Usenet-Provider http://www.giganews.com
NNTP-Posting-Host 75.8.126.96
X-Trace sv3-t29wmuliJbkp6iYLn3bk4Qq/JsyKRw6NKOTekGvC7ai5qb1qYJX22v5ITCHa3iG7Gu6JcGoFybVank6!8Kn9o0Kw0oQ+SynQpbP6gyQFRoAVk3H0g0Ot5FGKOZXfhq0ahJdPX73RbcsEwf8jnINZjeAgqJW4!X4hBiXnAQL0ilmdzTybCd6PiGhT8zJzvT9FMfv/JAvc=
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 2282
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.help:617

Show key headers only | View raw


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.

If neither of those ideas answers the actual question, please post an
example.

Patricia

Back to comp.lang.java.help | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

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