系统差异。 Java中的exit(0),System.exit(-1),System.exit(1) [英] Difference in System. exit(0) , System.exit(-1), System.exit(1 ) in Java
问题描述
我想知道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?
推荐答案
如果程序执行的好坏,退出的参数应符合条件。这是一种来自旧编程语言的遗传,知道出错是什么以及出了什么问题很有用。
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
,等等!= 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
是由由于不同的unix信号而终止,例如 SIGSEGV 或 SIGTERM
1-127
are user defined codes (so generated by callingexit(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屋!