System.exit
public static void exit(int status)
Terminates the currently running Java Virtual Machine.
The argument serves as a status code; by convention, a nonzero status code indicates abnormal termination. This method calls the exit method in class Runtime.
This method never returns normally.
The call System.exit(n) is effectively equivalent to the call:
Runtime.getRuntime().exit(n)
public static void exit(int status)
Terminates the currently running Java Virtual Machine.
The argument serves as a status code; by convention, a nonzero status code indicates abnormal termination. This method calls the exit method in class Runtime.
This method never returns normally.
The call System.exit(n) is effectively equivalent to the call:
Runtime.getRuntime().exit(n)
=>
对于java程序,运行System.exit()会终止JVM, 0表示正常退出,非0表示异常退出
举个例子,在bat里(但愿您会batch)
java abc.HelloWorld
ECHO exit=%ERRORLEVEL%
IF ERRORLEVEL 0 ECHO 正常结束,或者调用了System.exit(0)
IF ERRORLEVEL 1 ECHO System.exit(1)
其实两者都不是“正常”退出
try {
System.exit(0); //试试return或者throw
} finally {
System.out.println("!!!!!"); //这行,无论return, throw都会执行,但是System.exit却不是
}
java abc.HelloWorld
ECHO exit=%ERRORLEVEL%
IF ERRORLEVEL 0 ECHO 正常结束,或者调用了System.exit(0)
IF ERRORLEVEL 1 ECHO System.exit(1)
其实两者都不是“正常”退出
try {
System.exit(0); //试试return或者throw
} finally {
System.out.println("!!!!!"); //这行,无论return, throw都会执行,但是System.exit却不是
}
转载于:https://blog.51cto.com/tianya23/247041