Differences between Exception and Error in java >
Exception does not indicate any serious problem.
Error indicates some serious problems that our application should not try to catch.
Exception are divided into checked and unchecked exceptions.
Error are not divided further into such classifications.
Which classes are which type of exception? either
checked or unchecked exception?
The class Exception and all its subclasses that are not also subclasses of RuntimeException are checked exceptions.
The class RuntimeException and all its subclasses are unchecked exceptions.
The class Error and all its subclasses are unchecked exceptions.
Error and its subclasses are regarded as unchecked exceptions
Most frequently faced exception and errors
VirtualMachineError, IOError, AssertionError, ThreadDeath,
Why to catch or not to catch?
Application must catch the Exception because they does not cause any major threat to application.
Application must not catch the Error because they does cause any major threat to application.
Let’s say errors like OutOfMemoryError and StackOverflowError occur and are caught then JVM might not be able to free up memory for rest of application to execute, so it will be better if application don’t catch these errors and is allowed to terminate.
/** Copyright (c), AnkitMittal JavaMadeSoEasy.com */