System.exit

简介:
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却不是   
  }   


本文转自 tianya23 51CTO博客,原文链接:http://blog.51cto.com/tianya23/247041,如需转载请自行联系原作者
相关文章
|
5月前
System.exit(0)和System.exit(1)区别
System.exit(0)和System.exit(1)区别
|
5月前
|
Ubuntu Docker 容器
System has not been booted with systemd as init system (PID 1). Can‘t operate.
System has not been booted with systemd as init system (PID 1). Can‘t operate.
|
6月前
|
Windows
Windows 11 蓝屏 Stop code - SYSTEM SERVICE EXCEPTION What failed - igdkmd64.sys
Windows 11 蓝屏 Stop code - SYSTEM SERVICE EXCEPTION What failed - igdkmd64.sys
106 0
|
Perl
Command PhaseScriptExecution failed with a nonzero exit code问题解决
在某次pod install后,run项目出现以下错误
609 0
|
C++
ERROR: Command errored out with exit status 1:
ERROR: Command errored out with exit status 1:
209 0
ERROR: Command errored out with exit status 1:
ZCMU - 1992: Swiss-system tournament
ZCMU - 1992: Swiss-system tournament
87 0
|
网络协议 关系型数据库 网络安全
|
Oracle 关系型数据库 Java
|
Linux Windows Unix