Catch Two Exceptions, One the Superclass of Another
I have a factory method that is parsing text and creating an Object. In
this factory method, there is a section that reads until the end of a
stream. There is another method that I have written that implements this
part of the parser. Here is the code I'm using:
StringBuilder builder = new StringBuilder();
try {
while (reader.ready()) {
builder.append(reader.readLine());
}
} catch (EOFException e) {
// end method normally.
} catch (IOException e) {
throw e; // end method with an exception.
}
I want to treat the EOFException differently than the IOException, so I
catch them in different catch() blocks. My question is: after an
EOFException is thrown, will the IOException catch() block run? I suppose
I could use a boolean that will be set in the EOFException area and tested
in the IOException area, but this isn't as clean as I'd like it to be.
Sorry I didn't describe that well, and thanks in advance.
No comments:
Post a Comment