Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #577
| 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 | Fri, 22 Apr 2011 07:09:26 -0500 |
| Date | Fri, 22 Apr 2011 05:09:23 -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: Good practice or not to close the file before System.exit(1)? |
| References | <87mxjjqmlf.fsf@merciadriluca-station.MERCIADRILUCA> <v1e1r6h1no1rjhsuit8cf7rfpkh7b59889@4ax.com> <finally-20110422035708@ram.dialup.fu-berlin.de> <k4q2r6hhm9khdm84c9qncmc2j0430dtikh@4ax.com> |
| In-Reply-To | <k4q2r6hhm9khdm84c9qncmc2j0430dtikh@4ax.com> |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 8bit |
| Message-ID | <CqOdnTCcLoBr8izQnZ2dnUVZ_uOdnZ2d@earthlink.com> (permalink) |
| Lines | 28 |
| X-Usenet-Provider | http://www.giganews.com |
| NNTP-Posting-Host | 75.8.126.96 |
| X-Trace | sv3-gvAgkCEnGn2bZjqGey6ZeqkcvQaDwp+mLjSoU8iICVmnadnn2iDxX+qjDYqEBF0ZQdK9mTrk1x66AQY!9yTMpPNPWPWfQSjwz/QH12US1OjzJGPWz+yqf6j41JEP0YkSMwKiimBhCCOcR1MlqCdZgbOr7xEO!tPRMMTHPjan76IPcfbolMCtztBHiU4yPBO3NLQ6Pu1Q= |
| 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 | 2384 |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.java.help:577 |
Show key headers only | View raw
On 4/22/2011 4:39 AM, rossum wrote:
> On 22 Apr 2011 01:57:28 GMT, ram@zedat.fu-berlin.de (Stefan Ram)
> wrote:
>
>> rossum<rossum48@coldmail.com> writes:
>>> The standard way to do this is by putting the close in the finally
>>> block of a try ... finally. Have you covered them in your course yet?
>>
>> How would this help in
>>
>> BufferedReader inputFile = new BufferedReader(...);
>> try { ... System.exit( 1 ); }
>> finally { inputFile.close(); }
>>
>> ? I do not endorse writing »System.exit« in the middle of a program
>> as above, but I though that was what the OP wanted to do.
>>
> Good catch, my mistake. System.exit() bypasses any finally blocks.
> Ouch.
>
> To the OP: don't use System.exit(), throw an exception instead.
If the program should terminate with a non-zero status code, the OP has
to call System.exit(). Exceptions can only reduce the number of
different places where it is called, and put the calls at an appropriate
level in the call hierarchy.
Patricia
Back to comp.lang.java.help | Previous | Next — Previous in thread | Next in thread | Find similar
Good practice or not to close the file before System.exit(1)? Merciadri Luca <Luca.Merciadri@student.ulg.ac.be> - 2011-04-22 00:13 +0200
Re: Good practice or not to close the file before System.exit(1)? rossum <rossum48@coldmail.com> - 2011-04-22 00:11 +0100
Re: Good practice or not to close the file before System.exit(1)? rossum <rossum48@coldmail.com> - 2011-04-22 12:39 +0100
Re: Good practice or not to close the file before System.exit(1)? Patricia Shanahan <pats@acm.org> - 2011-04-22 05:09 -0700
Re: Good practice or not to close the file before System.exit(1)? Lew <noone@lewscanon.com> - 2011-04-22 09:39 -0400
Re: Good practice or not to close the file before System.exit(1)? Merciadri Luca <Luca.Merciadri@student.ulg.ac.be> - 2011-04-23 13:20 +0200
Re: Good practice or not to close the file before System.exit(1)? Merciadri Luca <Luca.Merciadri@student.ulg.ac.be> - 2011-04-22 16:37 +0200
Re: Good practice or not to close the file before System.exit(1)? Patricia Shanahan <pats@acm.org> - 2011-04-22 04:55 -0700
Re: Good practice or not to close the file before System.exit(1)? Merciadri Luca <Luca.Merciadri@student.ulg.ac.be> - 2011-04-22 13:56 +0200
Re: Good practice or not to close the file before System.exit(1)? Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-04-22 09:36 -0300
Re: Good practice or not to close the file before System.exit(1)? markspace <-@.> - 2011-04-22 08:20 -0700
Re: Good practice or not to close the file before System.exit(1)? Patricia Shanahan <pats@acm.org> - 2011-04-22 09:04 -0700
Re: Good practice or not to close the file before System.exit(1)? markspace <-@.> - 2011-04-22 15:24 -0700
Re: Good practice or not to close the file before System.exit(1)? markspace <-@.> - 2011-04-22 18:11 -0700
Re: Good practice or not to close the file before System.exit(1)? markspace <-@.> - 2011-04-23 08:25 -0700
Re: Good practice or not to close the file before System.exit(1)? Merciadri Luca <Luca.Merciadri@student.ulg.ac.be> - 2011-04-22 18:55 +0200
Re: Good practice or not to close the file before System.exit(1)? Lew <noone@lewscanon.com> - 2011-04-22 13:40 -0400
Re: Good practice or not to close the file before System.exit(1)? Patricia Shanahan <pats@acm.org> - 2011-04-22 10:55 -0700
Re: Good practice or not to close the file before System.exit(1)? Merciadri Luca <Luca.Merciadri@student.ulg.ac.be> - 2011-04-22 22:58 +0200
Re: Good practice or not to close the file before System.exit(1)? Merciadri Luca <Luca.Merciadri@student.ulg.ac.be> - 2011-04-22 23:09 +0200
Re: Good practice or not to close the file before System.exit(1)? Patricia Shanahan <pats@acm.org> - 2011-04-22 14:30 -0700
Re: Good practice or not to close the file before System.exit(1)? markspace <-@.> - 2011-04-22 15:38 -0700
Re: Good practice or not to close the file before System.exit(1)? Patricia Shanahan <pats@acm.org> - 2011-04-22 17:00 -0700
Re: Good practice or not to close the file before System.exit(1)? Lew <noone@lewscanon.com> - 2011-04-22 22:10 -0400
Re: Good practice or not to close the file before System.exit(1)? Patricia Shanahan <pats@acm.org> - 2011-04-22 19:46 -0700
Re: Good practice or not to close the file before System.exit(1)? Lew <noone@lewscanon.com> - 2011-04-23 09:54 -0400
Re: Good practice or not to close the file before System.exit(1)? Roedy Green <see_website@mindprod.com.invalid> - 2011-04-22 12:45 -0700
Re: Good practice or not to close the file before System.exit(1)? Merciadri Luca <Luca.Merciadri@student.ulg.ac.be> - 2011-04-22 23:20 +0200
csiph-web