Error and Exception Handling Flashcards
What are Errors in Java?
Serious, unrecoverable issues often caused by runtime, hardware, or software failures. Examples:
OutOfMemoryError
StackOverflowError
VirtualMachineError
What are Exceptions in Java?
Recoverable issues arising during program execution, such as:
NullPointerException
ArrayIndexOutOfBoundsException
FileNotFoundException
Hierarchy of Errors and Exceptions?
Both inherit from the Throwable class, the root of the exception hierarchy.
Difference Between Checked and Unchecked Exceptions?
Checked Exceptions:
External issues (e.g., file/network errors).
Must be handled using try-catch or declared with throws.
Examples: IOException, FileNotFoundException.
Unchecked Exceptions:
Programming errors (e.g., invalid arguments).
Handling not enforced by the compiler.
Examples: NullPointerException, ArithmeticException.
Purpose of finally
Block?
Executes crucial code (e.g., cleanup tasks) after try and catch, regardless of exceptions.