Multiple Catch

Unit 5 Β· Topic 5.8⏱ 8 min read❓ 5 MCQs

Introduction

Multiple catch blocks handle different exception types; catch(...) catches all.

Definition

Multiple Catch: separate handlers per type + catch-all.

C++ Code Example

try {
    throw 3.14f;
} catch (int i){ cout<<"int"; }
  catch (float f){ cout<<"float"; }
  catch (...){ cout<<"other"; }

Important Questions

Short Questions

  1. Can we have multiple catch?
  2. Order of catch blocks?
  3. What is catch(...)?
  4. Can catch all types?

Long Questions

  1. Explain multiple catch with example.
  2. Discuss catch-all.

MCQ Practice

1. Multiple catch blocks handle:

  • Different types
  • Same type
  • Nothing
  • All as one
Answer: Different types.

2. catch(...) catches:

  • Any exception
  • Only int
  • Only char
  • Nothing
Answer: Any exception.

3. Order should be:

  • Specific to general
  • General to specific
  • Any
  • None
Answer: Specific to general.

4. catch-all is useful for:

  • Unknown exceptions
  • Known types
  • Speed
  • None
Answer: Unknown exceptions.

5. Each catch handles:

  • One type
  • All types
  • Nothing
  • Files
Answer: One type.

Quick Revision

  • Multiple catch per type.
  • catch(...) catches all.