Junior — Middle
Can you name standard exceptions that can be checked in Java?
sobes.tech AI
Answer from AI
In Java, checked exceptions are exceptions that the compiler requires to be handled or declared in the method. Some standard checked exceptions:
IOException— input/output errors, for example when working with files or networks.SQLException— errors when working with databases via JDBC.ClassNotFoundException— when a class is not found during dynamic loading.InterruptedException— thread interruption.FileNotFoundException— file not found (subclass of IOException).
Example of handling a checked exception:
try {
FileInputStream fis = new FileInputStream("file.txt");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Checked exceptions force developers to explicitly handle potential errors, increasing code reliability.