What is a Runtime Exception?

Runtime Exception is the parent class in all exceptions of the Java programming language that are expected to crash or break down the program or application when they occur. Unlike exceptions that are not considered as Runtime Exceptions, Runtime Exceptions are never checked.

The Runtime Exception usually shows the programmer's error, rather than the condition a program is expected or assumed to deal with. Runtime Exceptions are also used when a condition that can't happen happens. It should be noted that when a program is running out of memory, a program error is thrown instead of showing it as a Runtime Exception.

This does not necessarily mean that it is often a good idea to catch a Runtime Exception. The application is not expected or assumed to deal with one; thus, unless an exception is assumed to be caused by unwanted input that the application can reject more cleanly (like the NumberFormatException caught by the built-in number of parsing algorithms) a Runtime Exception often represents a developer's or programmer's error. It is a lot better to allow these types of issues to terminate the program or application so that the error can be found.

The three most common Runtime Exceptions are the NullPointerException, ArrayIndexOutOfBoundsException, and the InvalidArgumentException. The Java Virtual Machine throws the first two Runtime Exceptions. They occur when C++ would provide a segmentation fault.

The NullPointerException is the exception thrown by the Java Virtual Machine when a user performs some operations on a certain object considered as null or is calling for some method on the null object. A user should not attempt to handle this kind of exception because it will only patch the problem and not completely fix it.

The ArrayIndexOutOfBoundsException is the exception that is automatically thrown by the JRE or Java Runtime Environment when a certain Java program incorrectly tries to access a certain location in a set that is non-existent. This often happens when the array index requested is negative, or more than or equal to the array's size. The arrays of Java use the zero-based indexing; thus, the very first element of that array has a zero index, the last element comes with an index of size 1, and the nth element generally comes with an index n-1.

The InvalidArgumentException is an exception raised when an invalid parameter is passed to a certain method on the server's referenced connection.

Windows and the Windows logo are trademarks of the Microsoft group of companies.
Microsoft is a registered trademark of Microsoft Corporation in the United States and/or other countries.