Understanding the exception hierarchy
Java is an object-oriented language, and objects can form a hierarchy. In Java, all exceptions are subclasses of the Throwable class. Everything that can be thrown by the application in case of a problem is of the Throwable type. The Throwable class has two main subclasses: Error and Exception.
Errors represent severe issues that occur during the runtime system’s operation, and they typically indicate critical problems with the JVM or the application environment. Examples include OutOfMemoryError and StackOverflowError. Errors are usually not recoverable, and it is not recommended to catch and handle them in your code.
On the other hand, the Exception class and its subclasses represent exceptional conditions that a program can handle. There are two main categories of exceptions: checked and unchecked exceptions.
Checked exceptions
Checked exceptions are exceptions that can be expected to happen, such as situations where we are...