Java - Exception HandlingWhich of the following is the correct syntax to catch multiple exceptions in a single catch block?Acatch (IOException | SQLException e) { }Bcatch (IOException, SQLException e) { }Ccatch (IOException & SQLException e) { }Dcatch (IOException; SQLException e) { }Check Answer
Step-by-Step SolutionSolution:Step 1: Recall Java syntax for multi-catchJava uses the pipe symbol '|' to catch multiple exceptions in one block.Step 2: Check each optionOnly catch (IOException | SQLException e) { } uses the correct '|' syntax; others use invalid separators.Final Answer:catch (IOException | SQLException e) { } -> Option AQuick Check:Multi-catch uses '|' = catch (IOException | SQLException e) { } [OK]Quick Trick: Use '|' to catch multiple exceptions in one catch [OK]Common Mistakes:Using commas or ampersands instead of '|'Trying to declare multiple exception variablesMissing parentheses around exceptions
Master "Exception Handling" in Java9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Java Quizzes Classes and Objects - Instance variables - Quiz 5medium Custom Exceptions - Throwing custom exceptions - Quiz 13medium Custom Exceptions - Throwing custom exceptions - Quiz 14medium Custom Exceptions - Throwing custom exceptions - Quiz 10hard Encapsulation - Encapsulation best practices - Quiz 1easy Encapsulation - Getter and setter methods - Quiz 12easy Exception Handling - Checked vs unchecked exceptions - Quiz 5medium Inheritance - Constructor chaining - Quiz 13medium Inheritance - Constructor chaining - Quiz 11easy Inheritance - Method overriding - Quiz 2easy