Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: changed EX2

...

EX1: It is reasonable to ignore handling an exception that occurs within a catch or finally block, such as when closing a FileInputStream object.

EX2: It is also permissible to ignore the handling an exception when the client cannot be expected to recover from the exception easily. it is not possible to recover from the exceptional condition at that abstraction level. In such cases, the exception must be thrown so that higher level code can try recovering from the exceptional condition by catching and handling it.

Code Block
bgColor#ccccff

// when recovery is possible at higher levels
private void doSomething() throws IOException {
  // 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
}

If the higher level code is also incapable of staging a recovery, the checked exception may be wrapped in an unchecked exception and re-thrown.

Code Block
bgColor#ccccff

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

Risk Assessment

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

...