简体   繁体   English

我怎么能故意创建一个简单的运行时错误?

[英]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.

相关问题 如何在 java 中故意创建随机浮点/十进制精度错误? - How can I intentionally create random floating point / decimal precision errors in java? 我可以在运行时创建 servlets 吗? - Can I create servlets at runtime? 如何解决这个简单的作用域错误? - How can I fix this simple scoping error? 如何在运行时启用/禁用JMS侦听器? 我可以创建一个可以在运行时启用/禁用侦听器的API吗? - How to enable/disable JMS listener on runtime? Can I create one api which enables/disables listener on runtime? 如何修复此代码的运行时错误? - How can I fix runtime Error of my this code? 如何使JVM运行时错误弹出窗口静音? - How can I silence JVM Runtime Error Popup? 如何在没有运行时错误的情况下读取 java 中的内部循环? - How can i read inside loop in java without runtime error? 如何解决 Java 处理应用程序中的运行时错误? - How can i resolve Runtime Error in Java Processing Application? 如何使用ANTLR创建一个简单的输入验证器? - How can I create a simple input validator by using ANTLR? 如何使用Apache POI创建简单的docx文件? - How can I create a simple docx file with Apache POI?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM