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

dwj*_*ton 5 java testing error-handling runtime-error

我正在测试批处理脚本,以检查它是否在运行编译的jar时处理任何错误.

什么是我可以添加到我的java中导致运行时错误的最简单的代码片段?

ars*_*jii 10

你可以简单地扔一个RuntimeException:

throw new RuntimeException("Test runtime exception");
Run Code Online (Sandbox Code Playgroud)

  • 在它之前添加一个`if(true)`语句 (2认同)