Skip to main content
PreparationZone Logo
PreparationZone
Back to Java

Java · Hard · Pro

Debug: why is the IOException swallowed?

JavaAdvanced JavaTrickyStaff

Callers never see failures from readConfig().

Java
public String readConfig() throws IOException {
    try (Reader r = openReader()) {
        return parse(r);
    } finally {
        return "default";
    }
}
Model answerPreview

Root cause

  • A return in finally suppresses any exception or return value from try.
  • Callers always get "default"; IOException…