Re: Good practice or not to close the file before System.exit(1)?
On 4/22/2011 8:20 AM, markspace wrote:
On 4/22/2011 4:56 AM, Merciadri Luca wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
The fact is that when some specific values of variables are
encountered, the program can't continue. I would have preferred
throwing an exception, but there is apparently no reason to throw
an exception because the variables that need to be checked come
directly from the arguments that the user passed to the JVM:
java myprogram 1 2 3
Doesn't matter, throw an exception.
....
In your particular case, yes you could almost certainly avoid opening
the files first. However in general this follows the same pattern
that all other exceptional processing follows: throw an error when
you have a problem, let the high level code catch it and deal with
the results.
To take the extreme case of high level code, what is the main method of
an application supposed to do when, through exceptions or otherwise, it
finds out that the program should terminate with status code 1?
Patricia