Sobes.tech
Junior — Middle

Can you name examples of Checked exceptions used in your experience?

sobes.tech AI

Answer from AI

In Java, checked exceptions are exceptions that are verified by the compiler, and they must either be handled or declared in the method signature using throws.

Examples of checked exceptions that are commonly encountered:

  • IOException — occurs during input/output errors, such as working with files or network streams.
  • SQLException — during database operations via JDBC.
  • ClassNotFoundException — when a class is not found during dynamic loading.
  • InterruptedException — when a thread is interrupted.

Example of handling a checked exception:

try {
    FileReader reader = new FileReader("file.txt");
    // reading the file
} catch (IOException e) {
    e.printStackTrace();
}

Using checked exceptions helps explicitly control errors that may occur during program execution.

Can you name examples of Checked exceptions used in… - sobes.tech