[英]How can I intentionally create a simple runtime error?
I'm testing a batch script, to check that it's handling any errors when a compiled jar is run. 我正在测试批处理脚本,以检查它是否在运行编译的jar时处理任何错误。
What's the simplest snippet of a code I can add to my java to cause a runtime error? 什么是我可以添加到我的java中导致运行时错误的最简单的代码片段?
您可以简单地抛出RuntimeException
:
throw new RuntimeException("Test runtime exception");
for (int i=0; i<1; i++){
int x = 10/i; // Arithmetic exception
}
在for循环之前声明x
然后键入x=10/i;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.