What is an Exception?
An exception is an unwanted or unexpected event, which occurs during the compilation or execution of a program, that disrupts the normal flow of the program’s instructions.
Error vs Exception
Error: An Error indicates a serious problem that a reasonable application should not try to catch.
Exception: Exception indicates conditions that a reason the application might try to catch.
All exception and error types are subclasses of class Throwable which is the base class of the hierarchy. One branch is headed by Exception, is used for exceptional conditions that programs should catch. NullPointerException is an example of such an exception.
Another branch, Error is used by the Java run-time system(JVM) to indicate errors having to do with the run-time environment itself(JRE). StackOverflowError is an example of such an error. Errors cannot handle in Java. See the detailed hierarchy below.