An exception is an unwanted or unexpected event. It pretends the normal flow of the program instructions, which can cause the application to stop abnormally. The Exception may occur due to developing mistakes by writing code, or the user enters invalid data.
Throwable class is the root class for all classes in Exception.
An Error is an irrecoverable condition such as Java virtual machine (JVM) running out of memory, memory leaks, stack overflow errors, infinite recursion, etc. Errors are usually beyond the programmer’s control, and we should not try to handle the mistakes.
Types of exceptions:
- Checked Exceptions (IOException)
- Un-Checked Exceptions (RuntimeException)
The compiler checks checked exceptions at the compile-time programmer is responsible for handling these exceptions. Checked exceptions is known as IOException.
FileNotFoundException usually occurs if we try to read data from any file which doesn’t exist or understanding with the wrong file name.
The compile does not check Un-Checked exceptions. These exceptions have occurred at runtime, So they are also referred to as Runtime Exception.
Exception handling is the way to handle run time exception and maintaining the normal flow of the application.