先看一下API文档中关于System类

exit

public static void exit(int status)
终止当前正在运行的 Java 虚拟机。参数用作状态码;根据惯例,非 0 的状态码表示异常终止。

该方法调用 Runtime 类中的 exit 方法。该方法永远不会正常返回。

调用 System.exit(n) 实际上等效于调用:

Runtime.getRuntime().exit(n)
参数:
status - 退出状态。
抛出:
SecurityException - 如果安全管理器存在并且其
checkExit 方法不允许以指定状态退出。
另请参见:
Runtime.exit(int)

写个小测试代码

public static void main(String[] args) {    try {        System.out.println("try");        /**         * throw new Exception();         * 控制台结果:try, Exception & finally         */        /**         * return;         * 控制台结果:try & finally         */        /**         * System.exit(0);         * 控制台结果:try         */    } catch (Exception e) {        System.out.println("Exception");    } finally {        System.out.println("finally");    }}