Re: Good practice or not to close the file before System.exit(1)?
email@example.com (Stefan Ram) writes:
Neither exceptions nor ?System.exit?, not even multiple return
statements per method are required for this. For an example:
There is something equivalent for Swing programs.
Often, a process is terminated by setting the JFrame flag
EXIT_ON_CLOSE. (Which vaguely resembles ?System.exit()?.)
frame.setDefaultCloseOperation( javax.swing.JFrame.EXIT_ON_CLOSE )
. However, when a program is written with proper resource
management, this is not necessary. The program just needs to
dispose() all dispose()able Swing resources as early as
possible. The process will terminate as soon as there is no
more Swing resource. (I here assume frames set up by
frame.setDefaultCloseOperation( javax.swing.JFrame.DO_NOTHING_ON_CLOSE );
.) (However, I don't know whether this is documented Swing
This has the nice effect that proper termination of the
process assures the programer of proper resource handling
(at least insofar as he now knows that certain Swing
resources are released).
I wrote programs that actually were written in a too
complicated way, because their purpose was to demonstrate a
strict rendition of MVC in Java, but by running these
program one can see the effect. They are visible on the