Checked vs unchecked exceptions

Figure 539. Checked and unchecked exceptions Slide presentation
Checked exception Unchecked exception
final Path
   sourcePath = Paths.get("/tmp/test.txt"),
   destPath = Paths.get("/tmp/copy.java");

// Compile time error:
// Unhandled java.io.IOException
Files.copy(sourcePath, destPath);
...
  • Errors outside program control, e.g. network, memory, file permissions, ...

  • Recovery is possible

  • Compile time check required

final String s = null;

// Compiles smoothly
System.out.println(s.length());
  • Programming errors: Division by zero, array index violation, ...

  • No real chance for recovery

  • To be avoided in the first place

  • No compile time check required.


Figure 540. Further readings Slide presentation

Figure 541. Checked and unchecked exceptions Slide presentation