How to catch multiple exceptions in Java?

To catch multiple exceptions in Java, use the pipe (|) operator.

Here's how you do it:

try { 
  // do something
} catch (NumberFormatException | IllegalStateException e) { 
  // handle it
}