如何检测JVM因错误异常而异常退出?

huangapple go评论94阅读模式
英文:

How to detect that the JVM exited abnormally due to an error?

问题

  1. 为什么在这种情况下没有错误代码?
  2. 在我没有收到错误代码的情况下,我如何检测到JVM没有运行的机会?
英文:

When invoking the JVM with wrong arguments, I'd expect it to exit with an error code:

java -x && echo ok || echo Failed AS EXPECTED
Unrecognized option: -x
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Failed AS EXPECTED

Now, if I use another unrecognized argument, it does exit promptly, but it doesn't return an error code:

# Now that's a CAPITAL X
java -X 2>/dev/null && echo ok || echo Failed AS EXPECTED
ok
  1. Why there's no error code in this case?
  2. How can I detect that the JVM didn't have a chance to run, given that I don't get an error
    code?

答案1

得分: 2

因为-X(大写的X)是一个有效的命令行参数,所以没有错误。

它会让Java将额外选项的帮助信息打印到错误流中。

英文:

There is no error because -X (capital x) is a valid command line argument.

It makes Java print help on extra options to the error stream.

huangapple
  • 本文由 发表于 2020年8月8日 00:03:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/63305420.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定