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?
A runtime error can be caused by poor programming practices. If the engineer loads his software with memory leaks, it can cause a runtime error. If software patches are available, they can be installed to fix this problem.
Here are some examples of common runtime errors you are sure to encounter: Misspelled or incorrectly capitalized variable and function names. Attempts to perform operations (such as math operations) on data of the wrong type (ex. attempting to subtract two variables that hold string values)
You can simply throw a RuntimeException
:
throw new RuntimeException("Test runtime exception");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With