系统差异.Java 中的 exit(0)、System.exit(-1)、System.exit(1) [英] Difference in System. exit(0) , System.exit(-1), System.exit(1 ) in Java

查看:36
本文介绍了系统差异.Java 中的 exit(0)、System.exit(-1)、System.exit(1)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道以下Java中的区别

I'd like to know the difference between the following in Java

System.exit(0);
System.exit(-1);
System.exit(1);

我什么时候必须适当地使用上面的代码?

When do I have to use the above code appropriately?

推荐答案

exit 参数应该限定程序执行的好坏.这是旧编程语言的一种遗传,知道是否出现问题以及出了什么问题很有用.

The parameter of exit should qualify if the execution of the program went good or bad. It's a sort of heredity from older programming languages where it's useful to know if something went wrong and what went wrong.

退出代码是

  • 0 执行正常时;
  • 1, -1, whatever != 0 当某些错误发生时,您可以为不同类型的错误使用不同的值.
  • 0 when execution went fine;
  • 1, -1, whatever != 0 when some error occurred, you can use different values for different kind of errors.

如果我是正确的,退出代码过去只是正数(我的意思是在 UNIX 中)并根据范围:

If I'm correct exit codes used to be just positive numbers (I mean in UNIX) and according to range:

  • 1-127 是用户定义的代码(因此通过调用 exit(n) 生成)
  • 128-255 是由于 SIGSEGVSIGTERM
  • 等不同的 unix 信号而由终止产生的代码
  • 1-127 are user defined codes (so generated by calling exit(n))
  • 128-255 are codes generated by termination due to different unix signals like SIGSEGV or SIGTERM

但我认为您在使用 Java 编码时不应该关心,这只是一些信息.如果您打算让您的程序与标准工具交互,它会很有用.

But I don't think you should care while coding on Java, it's just a bit of information. It's useful if you plan to make your programs interact with standard tools.

这篇关于系统差异.Java 中的 exit(0)、System.exit(-1)、System.exit(1)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆