Bird
Raised Fist0

Which of the following demonstrates the correct way to declare multiple catch blocks in C#?

easy📝 Syntax Q3 of Q15
C Sharp (C#) - Exception Handling

Which of the following demonstrates the correct way to declare multiple catch blocks in C#?

Atry { /* code */ } catch (FormatException e) { } catch (Exception e) { }
Btry { /* code */ } catch (Exception e) { } catch (FormatException e) { }
Ctry { /* code */ } catch { } catch (Exception e) { }
Dtry { /* code */ } catch (Exception e) { } catch
Step-by-Step Solution
Solution:
  1. Step 1: Understand catch block order

    Specific exceptions must come before general exceptions.
  2. Step 2: Analyze options

    try { /* code */ } catch (FormatException e) { } catch (Exception e) { } places FormatException before Exception, which is correct.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Specific before general catch blocks [OK]
Quick Trick: Place specific exceptions before general ones [OK]
Common Mistakes:
MISTAKES
  • Placing general exception before specific
  • Using incomplete catch syntax
  • Omitting exception type in catch

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Sharp (C#) Quizzes