Link to home
Create AccountLog in
Avatar of Ghyths
Ghyths

asked on

What's the different between system.exit(0); and system.exit(1), system.exit(-1) ..etc

What's the different between system.exit(0); and system.exit(1) or System.exit(-1) .etc

all of them make the same results isn't it ?
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

An exit code of 0 means there were no errors. Exit codes are otherwise pretty arbitrary and are mainly of use in shell scripts
Avatar of CandorZ
CandorZ

Exit codes are also used by the parent program to determine whether the child program finished its execution successfully or not. If yes then fine, if an unsuccessful code is returned, the parent program might have to deal with it (may be running the child again)
Avatar of Ghyths

ASKER

So what if it's -1 of 1 or whatever ?
Avatar of Ghyths

ASKER

Please try to add code as example :)
> So what if it's -1 of 1 or whatever ?

Its up to you to you and how you want to use it with your application.
There is no specific meaning for the values returned. You don't even need to return 0 when there are no errors.
Its just there to provide the ability to easily return a value to the calling application as candorZ explained above.
Why bother writing code, its already available on the internet, just search function exit codes.
Have a look Exit Codes
It depends upon the developed what steps to take for what exit codes
e.g.
function1(int a)
{
if (a==1)
return (1);
else if(a < 0)
return (-1);
else if(a == 0)
return (0);
}
main()
{
int z=10;
int b=function(z);
//so the b will have return value from the function
}
Well this was how exit codes are in a program, similarly is for the system, system.exit(x) is the return statement and it will pass the return value to the enivronment (may be windows/DOS shell/Unix shell, etc)
Avatar of Ghyths

ASKER

I need an example shows the different between System.exit(0)
and System.exit(1);


Regards
G
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Ghyths

ASKER

Somehow it's ok :)
:)