英文:
How to detect that the JVM exited abnormally due to an error?
问题
- 为什么在这种情况下没有错误代码?
- 在我没有收到错误代码的情况下,我如何检测到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
- Why there's no error code in this case?
- 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论