An independent editorial resource for Java practitioners.

Browse the discussion resource

Java Chronicles

Forum resource / language design

Catching multiple exceptions: good or bad?

An resourced discussion about grouping exception types when their recovery path is the same—and the design questions that remain when it is not.

Stored topic42 recorded repliesOriginally discussed January 2008
Laptop showing code beside notes for software development

Page 1 of 3 · 42 replies in the preserved thread

Back to thread list

Opening question

One handler, several exception types

The original discussion considered a proposed Java syntax for handling several exception types in one catch clause. The motivating example involved reflective construction, where a number of checked exceptions were all translated into the same application-level failure.

try {
    return constructor.newInstance(url, username, password);
} catch (InstantiationException | IllegalAccessException |
         InvocationTargetException | NoSuchMethodException e) {
    throw new PluginException(e);
}

The central question was not only whether a compact form would save repeated code. It was whether it would make intent clearer: these distinct failures share one deliberate recovery path.

Selected replies from the resource

Reply 01

A case for restraint

One view urged care before changing core language syntax. From this perspective, a shorter form is worthwhile only when it improves understanding rather than simply arranging the same information differently.

Reply 02

Reducing repeated handlers

Another response supported grouping types when every branch would otherwise repeat the same work. It noted that duplication can make maintenance harder and can lead to small inconsistencies when one copied handler is edited differently from another.

Reply 03

Intent should remain visible

Several participants drew an important boundary: grouped exceptions are suitable only when the treatment is genuinely identical. If one exception requires a different recovery action, it should retain its own catch block.

Reply 04

Look at the abstraction first

A more architectural reply argued that long exception lists can expose a weak boundary. A method may need to translate low-level failures into a smaller, domain-appropriate set rather than pass every implementation detail to its callers.

Reply 05

A useful comparison with grouped cases

Supporters compared the idea to grouping switch cases: distinct inputs can intentionally lead to one outcome. The value lies in naming that shared outcome directly, without broad catch-all handling.

Continue through the complete resourced topic.

Next page

Reading the record

A useful way to revisit old technical debates.

01 / Context

Begin with the problem

Start with the repeated handler and identify precisely which failures share an outcome.

02 / Compare

Separate syntax from design

Ask whether concise syntax clarifies intent or whether the exception boundary itself needs revision.

03 / Apply

Keep recovery specific

Group only cases that truly receive the same treatment; preserve distinct paths where behavior differs.

04 / Continue

Follow related threads

Use the forum index to trace adjacent questions about Java language craft and everyday engineering.