Bird
0
0

Which of the following is the correct syntax to catch multiple exceptions in a single catch block?

easy📝 Syntax Q3 of 15
Java - Exception Handling
Which 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) { }
Step-by-Step Solution
Solution:
  1. Step 1: Recall Java syntax for multi-catch

    Java uses the pipe symbol '|' to catch multiple exceptions in one block.
  2. Step 2: Check each option

    Only catch (IOException | SQLException e) { } uses the correct '|' syntax; others use invalid separators.
  3. Final Answer:

    catch (IOException | SQLException e) { } -> Option A
  4. Quick 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 variables
  • Missing parentheses around exceptions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes