Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Changed the 1st exception example to throw a more specific exception. Changed the 2nd exception example to wrap the troublesome exception when rethrowing it as an unchecked expression (more info is now included in the unchecked exception).

...

Code Block
bgColor#ccccff
try {
  // Requested file does not exist
}catch(FileNotFoundException e) { /* ask the user for a different filename */ }

...

Code Block
bgColor#ccccff
// when recovery is possible at higher levels
private void doSomething() throws IOExceptionFileNotFoundException {
  // Requested file does not exist; throws FileNotFoundException
  // Higher level code can handle it by displaying a dialog box and asking 
  // the user for the file name
}

...

Code Block
bgColor#ccccff
try {
  // Requested file does not exist
  // User is unable to supply the file name
}catch(FileNotFoundException e) { 
  throw new RuntimeException("Cannot proceed with operation"e);
}

Risk Assessment

Ignoring or suppressing exceptions violates the fail-safe criteria of an application.

...