Results 1 to 4 of 4
  1. #1
    antgaudi's Avatar
    antgaudi is offline Member
    Join Date
    Sep 2008
    Location
    Houston-TX
    Posts
    22
    Rep Power
    0

    Default System.exit 0 or 1?

    What is the difference b/w:
    System.exit(0);
    and
    System.exit(1);

    If I have the following code:
    public class MathMistake
    {
    public static void main(String[] args)
    {
    int num = 13, denom = 0, result;
    if (denom == 0)
    System.exit(1);
    result = num / denom;
    }
    }


    Would I get the same result if I use the 0 or 1 for System.exit? :confused:

    Thanks.
    "The minute you settle for less than you deserve, you get even less than you settled for." Maureen Dowd

  2. #2
    Nakira is offline Member
    Join Date
    Oct 2008
    Location
    Aberystwyth
    Posts
    55
    Rep Power
    0

    Default

    Quote Originally Posted by antgaudi View Post
    What is the difference b/w:
    System.exit(0);
    and
    System.exit(1);

    If I have the following code:
    public class MathMistake
    {
    public static void main(String[] args)
    {
    int num = 13, denom = 0, result;
    if (denom == 0)
    System.exit(1);
    result = num / denom;
    }
    }


    Would I get the same result if I use the 0 or 1 for System.exit? :confused:

    Thanks.
    Easiest way to find out is try it yourself. Try to find the differences but if you still not sure post back. :P

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by antgaudi View Post
    What is the difference b/w:
    System.exit(0);
    and
    System.exit(1);

    If I have the following code:
    public class MathMistake
    {
    public static void main(String[] args)
    {
    int num = 13, denom = 0, result;
    if (denom == 0)
    System.exit(1);
    result = num / denom;
    }
    }


    Would I get the same result if I use the 0 or 1 for System.exit? :confused:

    Thanks.
    Are you try that? If so what happen, what's the difference you have noticed in two cases?

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    The number is the "exit code" of the program. Generally 0 means the program executed and exited normally. Other than zero usually means an error occurred. Most programs use different exit codes for different "abnormal" exits and document them, that allows the program to be used in a script and evaluate it's exit status without having to do any kind of text evaluations.

Similar Threads

  1. [SOLVED] exit code 2
    By antgaudi in forum New To Java
    Replies: 2
    Last Post: 09-21-2008, 11:03 PM
  2. System.exit() in catch block.
    By new_2_java in forum Advanced Java
    Replies: 8
    Last Post: 06-24-2008, 04:45 PM
  3. system.exit(..)
    By ramakanta.majhi in forum New To Java
    Replies: 2
    Last Post: 06-14-2008, 02:28 AM
  4. help with System.exit (1) function call
    By katie in forum Advanced Java
    Replies: 2
    Last Post: 08-06-2007, 09:03 PM
  5. How to exit the program..
    By coco in forum New To Java
    Replies: 1
    Last Post: 08-01-2007, 06:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •