Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #571 > unrolled thread
| Started by | Merciadri Luca <Luca.Merciadri@student.ulg.ac.be> |
|---|---|
| First post | 2011-04-22 00:13 +0200 |
| Last post | 2011-04-22 23:20 +0200 |
| Articles | 8 on this page of 28 — 7 participants |
Back to article view | Back to comp.lang.java.help
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
Page 2 of 2 — ← Prev page 1 [2]
| From | Patricia Shanahan <pats@acm.org> |
|---|---|
| Date | 2011-04-22 14:30 -0700 |
| Message-ID | <S5qdnd_Hy-rGbizQnZ2dnUVZ_j2dnZ2d@earthlink.com> |
| In reply to | #591 |
On 4/22/2011 2:09 PM, Merciadri Luca wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Another question comes to my mind: > > 3) Let us consider that your main deals with I/O. Then, it is common > to use exceptions, e.g. IOException (for dealing with files for > example) or NumberFormatException (for parseInt for example). However, > it is disadviced to use exceptions in the main. As a result, I can > reasonably conclude that dealing with I/O should go into (a) seperate > classe[s], but is it really a good idea when you don't need to deal > with that much input from the user? There is no problem using exceptions inside main, as long as you catch them, so that they don't get thrown from main. Patricia
[toc] | [prev] | [next] | [standalone]
| From | markspace <-@.> |
|---|---|
| Date | 2011-04-22 15:38 -0700 |
| Message-ID | <iot00p$2q0$1@dont-email.me> |
| In reply to | #593 |
On 4/22/2011 2:30 PM, Patricia Shanahan wrote: > > There is no problem using exceptions inside main, as long as you catch > them, so that they don't get thrown from main. During development, throwing exceptions from main is fine because it gives the developer the most about of useful information. If you release a program into the wild, then yes, end-users might not want to see stack traces. Although, some might. It all depends on your user requirements. Some technically sophisticated users with access to your source code might prefer a stack trace. So I don't think there's any hard and fast rule that says always do or always don't. It depends on what you want the program to do.
[toc] | [prev] | [next] | [standalone]
| From | Patricia Shanahan <pats@acm.org> |
|---|---|
| Date | 2011-04-22 17:00 -0700 |
| Message-ID | <c4WdnY5-xd42iy_QnZ2dnUVZ_tqdnZ2d@earthlink.com> |
| In reply to | #595 |
On 4/22/2011 3:38 PM, markspace wrote: > On 4/22/2011 2:30 PM, Patricia Shanahan wrote: > >> >> There is no problem using exceptions inside main, as long as you catch >> them, so that they don't get thrown from main. > > During development, throwing exceptions from main is fine because it > gives the developer the most about of useful information. Yes, I was over-simplifying a bit. Patricia
[toc] | [prev] | [next] | [standalone]
| From | Lew <noone@lewscanon.com> |
|---|---|
| Date | 2011-04-22 22:10 -0400 |
| Message-ID | <iotcfi$gno$1@news.albasani.net> |
| In reply to | #596 |
Patricia Shanahan wrote: > markspace wrote: >> Patricia Shanahan wrote: >> >>> >>> There is no problem using exceptions inside main, as long as you catch >>> them, so that they don't get thrown from main. >> >> During development, throwing exceptions from main is fine because it >> gives the developer the most about of useful information. > > Yes, I was over-simplifying a bit. I disagree. Throwing exceptions from main() provides no benefit that logging doesn't provide better. I'm using "main()" as a catch-all term for the top business layer of an application, be it a Java application, applet, web app, service or whatever. The observable behavior must conform to the problem domain being solved by the application. Emitting implementation-level messages at the business-domain level is inappropriate unless the business domain *is* the implementation. Even there, there is a conceptual difference between the business domain and the implementation domain. Design your business logic to be business logic. DO NOT make the mistake of "temporarily" inserting inappropriate code thinking, "We can pull this out later for production." Later doesn't come around enough to count on that. Design it right from day one and do not stray from being good. -- Lew Honi soit qui mal y pense. http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg
[toc] | [prev] | [next] | [standalone]
| From | Patricia Shanahan <pats@acm.org> |
|---|---|
| Date | 2011-04-22 19:46 -0700 |
| Message-ID | <-6mdnX7le_QCoC_QnZ2dnUVZ_v6dnZ2d@earthlink.com> |
| In reply to | #600 |
On 4/22/2011 7:10 PM, Lew wrote: > Patricia Shanahan wrote: >> markspace wrote: >>> Patricia Shanahan wrote: >>> >>>> >>>> There is no problem using exceptions inside main, as long as you catch >>>> them, so that they don't get thrown from main. >>> >>> During development, throwing exceptions from main is fine because it >>> gives the developer the most about of useful information. >> >> Yes, I was over-simplifying a bit. > > I disagree. Throwing exceptions from main() provides no benefit that > logging doesn't provide better. The benefit is simplicity. I often write short test programs, for example when looking into a newsgroup question, for which I'm the only user and that will only be run once. Just sticking "throws Exception" on main is simpler than catching exceptions and logging them. Patricia
[toc] | [prev] | [next] | [standalone]
| From | Lew <noone@lewscanon.com> |
|---|---|
| Date | 2011-04-23 09:54 -0400 |
| Message-ID | <iouln5$imi$1@news.albasani.net> |
| In reply to | #601 |
Patricia Shanahan wrote: > Lew wrote: >> Patricia Shanahan wrote: >>> markspace wrote: >>>> Patricia Shanahan wrote: >>>> >>>>> >>>>> There is no problem using exceptions inside main, as long as you catch >>>>> them, so that they don't get thrown from main. >>>> >>>> During development, throwing exceptions from main is fine because it >>>> gives the developer the most about of useful information. >>> >>> Yes, I was over-simplifying a bit. >> >> I disagree. Throwing exceptions from main() provides no benefit that >> logging doesn't provide better. > The benefit is simplicity. > > I often write short test programs, for example when looking into a > newsgroup question, for which I'm the only user and that will only be > run once. Just sticking "throws Exception" on main is simpler than > catching exceptions and logging them. I repeat the part that you omitted, which changes the sense of the comment you cited, > I'm using "main()" as a catch-all term for the top business layer of an application, > be it a Java application, applet, web app, service or whatever. > The observable behavior must conform to the problem domain being solved by the application. > Emitting implementation-level messages at the business-domain level is inappropriate > unless the business domain *is* the implementation. You speak of the case where the implementation is the domain, which I explicitly called out as a case where I agree that exceptions can be useful in the "main". Thanks for elucidating that point. -- Lew Honi soit qui mal y pense. http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg
[toc] | [prev] | [next] | [standalone]
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Date | 2011-04-22 12:45 -0700 |
| Message-ID | <hbm3r615r2bk7bd2mu6i9sebgvnci1u5gs@4ax.com> |
| In reply to | #571 |
On Fri, 22 Apr 2011 00:13:48 +0200, Merciadri Luca <Luca.Merciadri@student.ulg.ac.be> wrote, quoted or indirectly quoted someone who said : >In some cases, I need to make a System.exit(1) in my program. However, >a file has been opened some time before, and it has not been yet >closed. Do I need to close it for good practice? How is it handled by >Java if I don't close the file? This is not FORTRAN. Java does not close files for you if you don't. If you were writing, the final buffers full would not get written. The OS of course would close the files at that level, but it knows nothing of the buffers. -- Roedy Green Canadian Mind Products http://mindprod.com Politicians complain that Kindles and iBooks are killing jobs by destroying the paper book industry. I see it that they have create a way to produce books for less than a third the cost without destroying forests and emitting greenhouse gases in the process. They have created wealth. They are encouraging literacy and cutting the costs of education.
[toc] | [prev] | [next] | [standalone]
| From | Merciadri Luca <Luca.Merciadri@student.ulg.ac.be> |
|---|---|
| Date | 2011-04-22 23:20 +0200 |
| Message-ID | <8739la56fc.fsf@merciadriluca-station.MERCIADRILUCA> |
| In reply to | #589 |
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Roedy Green <see_website@mindprod.com.invalid> writes: > On Fri, 22 Apr 2011 00:13:48 +0200, Merciadri Luca > <Luca.Merciadri@student.ulg.ac.be> wrote, quoted or indirectly quoted > someone who said : > >>In some cases, I need to make a System.exit(1) in my program. However, >>a file has been opened some time before, and it has not been yet >>closed. Do I need to close it for good practice? How is it handled by >>Java if I don't close the file? > > This is not FORTRAN. Java does not close files for you if you don't. > If you were writing, the final buffers full would not get written. The > OS of course would close the files at that level, but it knows nothing > of the buffers. 4) I knew this, and I've now changed everything that had to be changed regarding the files' closing, be it for input or output. However, I was wondering... if you don't close a file opened for reading, what does it actually change? The way UNIX deals with files fortunately never locks a[n] (currently) opened file. I simply ask what kind of problems the non-closing of an opened file for reading would cause. (Consider here that I only speak about the UNIX case; I know that Java is evidently platform independent; as a result, one might want to depend only on the VM and not on the OS. I just want to be informed about the kind of troubles it might cause, and how the non-closing is dealt.) - -- Merciadri Luca See http://www.student.montefiore.ulg.ac.be/~merciadri/ - -- First deserve, then desire. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/> iEYEARECAAYFAk2x8TcACgkQM0LLzLt8MhydiACfTU7tMHXSXY6lM+mIMj1CYn5O AWgAoKrE6+kmAYDuahVkEbPiOiQ0LToS =FEVU -----END PGP SIGNATURE-----
[toc] | [prev] | [standalone]
Page 2 of 2 — ← Prev page 1 [2]
Back to top | Article view | comp.lang.java.help
csiph-web