|
Re: don't understand why checked exceptions get swallowed.
|
Posted: Jul 25, 2003 1:32 AM
|
|
In the following example, the declaration statement must be surrounded by the try/catch construct because the FileNotFound exception must be handled.
try
{
FileInputStream fis = new FileInputStream("ImportantFile");
}
catch (FileNotFoundException e)
{
// ToDo. Handle the file exception here.
// (Perhaps it will never happen. Do nothing.)
}
The exception is caught in the catch section but all that section contains is a comment. Nothing is done to handle the exception, thus it is 'swallowed'. The compiler is happy and the code will execute but if an exception did occur it would be ignored and the code following may well fall over in an ungy - and perhaps difficult to debug - heap because it assumed that it was in possesion of a valid FileInputStream object.
Incidentally; Bruce has a lot to say about the pros and cons of checked exceptions on his web site www.mindwiew.com. However, I would make sure you are happy with exceptions in your own head before you look at it, since both the case against them that he puts and the ensuing debate would be somewhat confusing to a beginner.
Vince.
PS. Isn't finding never done 'todo' comments in other people's code an uplifting experience. Not. :(
|
|