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?
You can simply throw a RuntimeException:
throw new RuntimeException("Test runtime exception");
unreachable statement compilation error?if (true) statement before itfor (int i=0; i<1; i++){
int x = 10/i; // Arithmetic exception
}
if(true) instead of loop, if you like. Just some another way of doing wht OP wants :)