Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 731
dwjohnston Avatar asked Nov 08 '13 01:11

dwjohnston


People also ask

How can you cause a runtime error to occur?

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.

What is an example of a runtime error?

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)


1 Answers

You can simply throw a RuntimeException:

throw new RuntimeException("Test runtime exception");
like image 70
arshajii Avatar answered Nov 14 '22 23:11

arshajii