BackendBench
Coffee
Spot the Bug #37

The settings file that quietly did not load

A easy Java puzzle in the exception handling mistakes family. One line below contains a real bug. Try to spot it first, then read why it fails and how to fix it.

easyException handling mistakesbuggy line: 9

Highlighted: line 9. Play this one as a puzzle without the answer.

What is wrong

The empty catch block discards the failure. If the file is missing or unreadable, the method returns an empty Properties object and the application runs with defaults, with nothing in the log to explain why. The bug surfaces much later as a wrong behavior.

The fix

} catch (IOException e) { throw new UncheckedIOException("Cannot load settings from " + path, e); }

How to avoid it next time

Never leave a catch block empty. Rethrow with context, log with the exception, or document why ignoring is correct.

Want the background? Read Exceptions: try, catch, throw in the Java concepts library.

About exception handling mistakes

Swallowed exceptions, lost causes and returns in finally blocks hide failures until the data is already wrong. The program keeps running and nobody knows why the result is missing.

In code review: An empty catch block, a catch that only prints, or an exception rethrown without its cause are all red flags. Log with the exception object and rethrow or handle meaningfully.

More puzzles in this family

๐Ÿž Play today's puzzleAll 132 bugsโ† #36#38 โ†’

Frequently asked questions

What is the bug in "The settings file that quietly did not load"?

The empty catch block discards the failure. If the file is missing or unreadable, the method returns an empty Properties object and the application runs with defaults, with nothing in the log to explain why. The bug surfaces much later as a wrong behavior. The faulty line is line 9: } catch (IOException e) {

How do I fix it?

Replace it with: } catch (IOException e) { throw new UncheckedIOException("Cannot load settings from " + path, e); }. Never leave a catch block empty. Rethrow with context, log with the exception, or document why ignoring is correct.

How do I catch exception handling mistakes in code review?

An empty catch block, a catch that only prints, or an exception rethrown without its cause are all red flags. Log with the exception object and rethrow or handle meaningfully.

Is there a new puzzle every day?

Yes. The daily Spot the Bug puzzle picks one of these snippets for each UTC day, with the difficulty set by the weekday. Your streak is stored only in your browser.

More tools you might need