Language syntax
Java Multi-catch
Handles unrelated exception alternatives with one block.
Formal Syntax & Structure
java syntaxjava
catch (A | B e) { ... }Working Example
Example Snippetjava
public class Main { public static void main(String[] args) { String[] inputs = {"abc", "0", "4"}; for (String input : inputs) { try { System.out.println(20 / Integer.parseInt(input)); } catch (NumberFormatException | ArithmeticException e) { System.out.println("Invalid divisor"); } } }}