...
Code Block |
---|
|
try {
// Requested file does not exist
}catch(FileNotFoundException e) { /* ask the user for a different filename */ }
|
...
Code Block |
---|
|
// 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 |
---|
|
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.
...