• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NX: closing of the application (System.exit(0), System.exit(n))

 
Ulrich Heeger
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,
In the API concerning System.exit its written:

Terminates the currently running Java Virtual Machine. The argument serves as a status code; by convention, a nonzero status code indicates abnormal termination.

Will it have different effects to the application if I choose System.exit(0) or System.exit(n) with n as a nonzero value?
For example I have an application closing if some fatal exception occurs, inviting me to make a System.exit(-1) call. Whereas if the User clicks the quit-Button of the Server GUI it would make sense to closing the application with System.exit(0)?
Or does the parameter just name the reason of the termination without any further effect to the application?
Thanks a lot in advance
Ulrich
 
Javini Javono
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
If n == 0, and System.exit(n) is called, it tells any "listening"
application that your application has completed without error.
For instance, JEdit has a JCompiler within it, and it probably uses
the return code to determine if the Sun, Java compiler completed
with or without error.
So, other system processes can, I presume, sense the return code
assuming that these processes are running within the same command
file (.sh for Unix, or .bat for Windows).
Now, keep in mind, that I don't write batch processes, but this is my
understanding.
If n != 0, then the error code might be looked up in a user's manual
to determine what the problem was for your application. However,
presumably, a quite detailed error message in English and a stack
trace are already available for our Java applications because we wrote
them that way, so in a sense, the error code is old fashioned
and not relevant. Perhaps, then, just one non-zero value is sufficient
for our applications if they experience any error of any type.
Keep in mind, of course, that you would only use n != 0 and call
System.exit(n) if your program had to terminate due to some error.
This is usually pretty rare, I would think.
For me, personally, and at this time, and subject to change, there does
exist one case where my program will force an exit: this is when the
calls to unlock() fail; for then I want the application to quit because
something is wrong with the database and this is a severe error; I also
want the application to quit because I want the records, which are
still locked on the server, to be released as soon as possible.
In short, the value of n, whether n == 0 or n != 0, definitely will not
effect your particular application in any way.
Thanks,
Javini Javono
[ May 07, 2004: Message edited by: Javini Javono ]
 
Ulrich Heeger
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Javini,
thanks a lot for your really informativ request.
So, I will keep my System.exit(-1) call.
Regards
Ulrich
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic