Exception handling
An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program's instructions.
Types of exceptions
- Checked exception
- Error
- Runtime exception
- Checked exceptions are checked at compile time. If a code throws a checked exception, then the associated block or method must handle the exception. For example,
FileNotFoundException
is a checked exception. If a method creates theFileInputStream
object to read data from, a file must handleFileNotFoundException
. If the specified file does not exist, thenFileNotFoundException
occurs and this exception must be caught or thrown. - Errors are exceptional conditions that are external to the application and it's not possible to anticipate and recover from them, for example, hardware failure, stack overflow error, and out of memory error. These errors should not be handled.
- Runtime exceptions are unchecked exceptions and these exceptions are not checked at compile time. Runtime...