... prompted for input. We’ll soon take a deeper look at how this flow of control works in exception handling.

Multi-catch

It’s relatively common for a try block to be followed by several catch blocks to handle various types of exceptions. If the bodies of several catch blocks are identical, you can use the multi-catch feature to catch those exception types in a single catch handler and perform the same task. The syntax for a multi-catch is:

catch (Type1 | Type2 | Type3 e)

Each exception type is separated from the next with a vertical ...

Get Java How to Program, Early Objects, 11th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.