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)
=>
對於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卻不是 }