`
rautinee
  • 浏览: 96380 次
  • 来自: 成都 四川
社区版块
存档分类
最新评论

return和System.exit(0)的不同[转贴]

    博客分类:
  • Java
阅读更多
如果我在public static void main(String[] args) 
中的某一行程式碼加上return;會使JVM得跳離main() 
也就是結束程式,那請問和寫System.exit(0)有何不同呢?
因為是在 public static void main(String[] args) 中 return... 
   所以其效果等同於 System.exit( ) ... 
   但是只要離開這個 method 之中... 
   那就會明顯的不同.... 
   也許可以這麼說... 
    return => 回到上一層... 
    System.exit() => 回到最上層...
 
System.exit(0) 應該是一種中斷JVM的指令吧

連finally block遇到System.exit(0)之後都沒有辦法繼續執行了

從 System.exit() 來看,其實參數不管放什麼值,程式都會被終止,
但這個值可以被呼叫它的程式捕捉。例如我們可以在 Windows 寫一支批次檔,
用來執行這支程式,當程式執行完成或中斷後,exit() 的參數就會被傳出,
接著我們就可以判斷 ERRORLEVEL (傳出的值會放在這個變數) 來決定下一步要做什麼
了。

分享到:
评论

相关推荐

    Python中exit、return、sys.exit()等使用实例和区别

    主要介绍了Python中exit、return、sys.exit()等使用实例和区别,本文是一个实际项目中的总结,需要的朋友可以参考下

    exit和abort及return的区别

    介绍C语言代码中的exit和abort及return的区别 exit() 结束当前进程/程序,在整个程序中,只要调用 exit ,就结束。 return() 是当前函数返回,当然如果是在主函数 main, 自然也就结束当前 进程了,如果不是,那就是...

    C#高仿QQ截图

    /// /// 一个强类型的资源类,用于查找本地化的字符串等。 /// // 此类是由 StronglyTypedResourceBuilder // 类通过类似于 ResGen 或 Visual Studio 的工具... return ((System.Drawing.Bitmap)(obj)); } }

    Visual C++中exit()和return的选择和使用

    Visual C++中exit()和return的选择和使用

    关于return的返回值.docx

    关于return的返回值.docx

    C语言中Return的用法.pdf

    C语言中Return的用法.pdf C 语言中Return 用法 1.含义:return 表示从被调函数返回到主调函数继续执行,返回时可 附带一个返回值,返回值可以是一个常量,变量,或是表达 式。 2.作用: 结束正在运行的函数,并返回...

    return_dbl.rar_return

    Check return value double.

    EmvReader Java Code

    System.out.println("#ERROR# Invalid reader index '"+args[0]+"'. Last valid index is " + (terminals.size()-1) ); System.exit(3); // throw new Exception( "Invalid reader index '"+iReader+"'. Last ...

    十六进制和RGB颜色互转

    return System.Drawing.Color.FromArgb(0, 0, 0);//设为黑色 } else {//转换颜色 return System.Drawing.Color.FromArgb(System.Int32.Parse(strHxColor.Substring(1, 2), System.Globalization.NumberStyles....

    C语言中return的作用.pdf

    C语言中return的作用.pdf

    java用类实现异常的处理的实例

    import java.util.*; class MyException extends Exception{ String message; MyException(int age){ message=age+"年龄异常";... System.exit(0); } System.out.println(a.getAge()); } }

    return_dbl.rar_float

    Check return value float.

    反射与接口

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 第三方公司插件 { using 记事本公司提供的插件标准; public class PlugOne:I...

    vb.net中的碎片发生器

    Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox Friend WithEvents txtMin As System.Windows.Forms.TextBox Friend WithEvents txtMax As System.Windows.Forms.TextBox Friend WithEvents ...

    c#编写的计算器

    this.btn_0 = new System.Windows.Forms.Button(); this.btn_mul = new System.Windows.Forms.Button(); this.btn_sub = new System.Windows.Forms.Button(); this.btn_sign = new System.Windows.Forms.Button...

    Java中return语句实例.pdf

    Java中return语句实例.pdf 学习资料 复习资料 教学资源

    python猜数字游戏-07-return的特点.ev4.rar

    python猜数字游戏-07-return的特点.ev4.rar

    酒店系统管理C#语言开发的

    this.groupBox2.Location = new System.Drawing.Point(0, 336); this.groupBox2.Name = "groupBox2"; this.groupBox2.Size = new System.Drawing.Size(728, 160); // // da1 // this.da1....

Global site tag (gtag.js) - Google Analytics