• Post Reply Bookmark Topic Watch Topic
  • New Topic

System.exit(x)  RSS feed

 
Ranch Hand
Posts: 401
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

May I know what is the diffrence between the 0 and other number we use in place of x in System.exit(x);.

Some times i see 1 in some programmes and some times i see 0 in some programmes , but I dont know where to use what and why. could anybody plese explain me .

rahul
 
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The number is the exit status. Usually a 0 indicates that the program ended normally. A non-zero number indicates that it terminated abnormally.
 
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most operating systems provide ways to query the exit value, for example from windows-bat-files or linux-shell-scripts.
 
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i would add this... if you are running your java program from a command line, then it probably doesn't make much difference.

but i often call various programs from a perl script. the return value of each can be caught by my perl script, and examined. if i get a value of 0, i know things worked just fine. if i get some other value, i can do different things in my script depending on what that number is - assuming i know what the numbers mean.

it's along the lines of any other method you may write that returns some kind of integer. For example, sometimes a comparison operator will return -1, 0 or 1 for A<B, A==B, or A>B respectivly.

when you call System.exit(<someValue>) , you are returning that integer to what started your code - the OS, a perl script... whatever. what you do with it, and what it specifically means, is up to you.
[ November 27, 2006: Message edited by: fred rosenberger ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!