Multiple Catch
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
- Can we have multiple catch?
- Order of catch blocks?
- What is catch(...)?
- Can catch all types?
Long Questions
- Explain multiple catch with example.
- 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.