javatestingerror-handlingruntime-error

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.

What's the simplest snippet of a code I can add to my java to cause a runtime error?


Solution

  • You can simply throw a RuntimeException:

    throw new RuntimeException("Test runtime exception");