...
Note that even though the application reacts to the exception by printing out a stack trace, it proceeds as though the exception were not thrown. That is, the future behavior of the application is unaffected by the throwing of the exception, other than the fact that statements in the try block after the statement that caused the exception are skipped. The IOException
indicates that an I/O operation attempted by the application failed; it is unlikely that assuming that the attempted operation succeeded will permit the application to operate correctlyexcept that any expressions or statement that occurs after the point from which the exception is thrown are not evaluated.
Compliant Solution (
...
Interactive)
This compliant solution attempts to recover from a FileNotFoundException
by forcing requesting that the user to specify another file when a particular file cannot be found in the user-specific directoryname.
Code Block | ||
---|---|---|
| ||
boolean volatile validFlag = false; do { try { // If requested file does not exist, throws FileNotFoundException // If requested file exists, sets a Boolean flag validFlag to true validFlag = true; } catch (FileNotFoundException e) { // Ask the user for a different filenamefile name } } while (validFlag != true); // Use the file |
...