Managing FastAPI Projects with Poetry: A Step-by-Step Guide

In Java, exceptions are categorized into Checked Exceptions and Unchecked Exceptions, depending on how the compiler and exception handling mechanisms operate.
Throwable
├─ Error (Unchecked)
└─ Exception
├─ CheckedException (e.g., IOException)
└─ RuntimeException (Unchecked)
Type | Inheritance Hierarchy | Compiler Enforcement | Common Examples |
---|---|---|---|
Checked Exception | Exception (excluding RuntimeException ) |
Required | IOException , SQLException |
Unchecked Exception | RuntimeException and its subclasses |
Not Required | NullPointerException , IllegalArgumentException |
Exception
, excluding RuntimeException
try-catch
or declare them with throws
IOException
SQLException
FileNotFoundException
ClassNotFoundException
RuntimeException
NullPointerException
ArrayIndexOutOfBoundsException
IllegalArgumentException
try {
FileInputStream fis = new FileInputStream("file.txt");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
int[] arr = new int[3];
System.out.println(arr[5]); // May throw ArrayIndexOutOfBoundsException
External, Predictable Factors
Checked exceptions arise from conditions outside the program's control, such as file I/O, network issues, or database access. These are predictable events that could happen even during normal program usage.
Compiler Enforcement Improves Stability
By requiring developers to handle or declare these exceptions, the compiler ensures greater reliability and fault tolerance.
Logical or Programming Errors
Unchecked exceptions typically occur due to developer mistakes—such as accessing a null reference or going out of array bounds. These are better prevented by fixing the code, rather than catching them.
Avoiding Code Bloat and Hidden Bugs
Forcing exception handling in every case could clutter the code with unnecessary try-catch
blocks and potentially hide bugs. Java allows developers to decide when handling is appropriate for such cases.
Comments
Post a Comment