Runtime exceptions in java

RuntimeExceptions are those exceptions which are checked at runtime. RuntimeException is the superclass of all those exceptions that can be thrown during the normal execution of the Java program. These are also called as unchecked exceptions. RuntimeException and their subclasses are known as unchecked exceptions. RuntimeExceptions can be avoided by programmer.

Examples – ArithmeticException, ArrayStoreException, CannotRedoException, CannotUndoException, ClassCastException, CMMException, ConcurrentModificationException, EmptyStackException, IllegalArgumentException, IllegalMonitorStateException, IllegalPathStateException, IllegalStateException, ImageFormatException, ImagingOpException, IndexOutOfBoundsException, MissingResourceException, NegativeArraySizeException, NoSuchElementException, NullPointerException, ProfileDataException, ProviderException, RasterFormatException, SecurityException, SystemException, TruncatedFileException, UnsupportedOperationException etc.

public class Main { 
 
	public static void main(String[] args) 
	{ 
		int a= 30, b = 0; 
 
		// Try to divide by zero 
		try { 
			int result = a / b; 
		} 
		catch (ArithmeticException e) { 
		    System.out.println(e.getClass().getName());
			e.printStackTrace(); 
		} 
	} 
}

Output

java.lang.ArithmeticException 
java.lang.ArithmeticException: / by zero
        at Main.main(Main.java:9)

Java interview questions on Exception Handling