...
Code Block | ||
---|---|---|
| ||
try {
//...
}catch(IOException ioe) { /* ignore */ }
|
...
Printing the exception's stack trace can be useful for debugging but is equivalent to ignoring the exception, as this noncompliant code example demonstrates.
Code Block | ||
---|---|---|
| ||
try {
//...
}catch(IOException ioe) { ioe.printStacktrace(); }
|
...
Code Block | ||
---|---|---|
| ||
try {
// Requested file does not exist
}catch(IOException) { /* ask the user for a different filename */ }
|
Wiki Markup |
---|
Although, not explicitly required by this recommendation, failure tolerant systems must also catch and handle unexpected unchecked exceptions resulting from programming errors. In all other cases, refrain from using the {{throws}} clause to force the client into dealing with unchecked exceptions \[[Bloch 08|AA. Java References#Bloch 08]\]. |
Exceptions
EX1: It is reasonable to ignore an exception which that occurs within a catch
or finally
block, such as while trying to close when closing a FileInputStream
object.
EX2: It is also permissible to ignore the exception when the client cannot be expected to recover from the exception easily.
...