Contents of page :
- System.exit(-1)>
- System.exit(0) >
- System.exit(1) >
A) Difference between System.exit(-1), System.exit(0) and System.exit(1) methods in java.
System.exit(-1)>
- If exit method returns -1 or some other negative number that means some error occurred,
- Its Abnormal termination.
System.exit(0) >
- If exit method returns 0 that means method execution was successful.
- Its Normal termination.
System.exit(1) >
- If exit method returns 1 or some other positive number that means some exception occurred,
- These may be user defined codes to indicate the exception occurred which user could have expected.
- Its Abnormal termination.
B) Let’s learn about System.exit(n) method in java >
- System.exit terminates JVM.
- Parameter
- Passing zero as parameter means normal termination &
- Passing non-zero as parameter means abnormal termination.
- System.exit(n) internally calls Runtime.getRuntime().exit(n)
Also read Program to show what will happen when catch and finally both return some value. Click here.
SUMMARY >
Difference between System.exit(-1), System.exit(0) and System.exit(1) methods in java.
System.exit(-1)>
System.exit(0) >
- Normal termination. Method execution was successful.
System.exit(1) >
RELATED LINKS>
Labels:
Core Java
Exceptions