Exceptions in Java
Exceptions in Java
In Java, exceptions are used to handle errors and other exceptional events in a program.
They are categorized into two main types: checked exceptions and unchecked
exceptions. Below are the main exception types and their key details
1. Checked Exceptions
Checked exceptions are checked at compile-time, meaning the compiler ensures that the
exception is either caught or declared to be thrown.
Examples:
Unchecked exceptions are not checked at compile-time, and they occur due to logical
errors in the program. These exceptions inherit from RuntimeException.
Examples:
3. Errors
Errors are serious issues that applications typically cannot recover from. These are not
exceptions but are part of the java.lang.Error class.
Examples:
• OutOfMemoryError: Thrown when the Java Virtual Machine (JVM) runs out of
memory.