The 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 to deal with. Runtime Exceptions are also used when a condition that can't happen. 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.
The most common Runtime Exceptions are NullPointerException, ArrayIndexOutOfBoundsException and the InvalidArgumentException. The Java Virtual Machine throws the first two Runtime Exceptions.
public class MyExceptionTest { public void testRuntimeException () { throw new MyException(); } public static void main(String[] args) { try { new MyExceptionTest().testRuntimeException(); } catch(Exception e) { System.out.println(e.getClass().getName()); } } } class MyException extends RuntimeException { public MyException() { super(); } }
MyException