← Quiz: Exception Handling in C++: all 10 questions
Quiz: Exception Handling in C++ · Question 3 of 10
Why should you catch exceptions by const reference?
Why should you catch exceptions by const reference?
- A.References are required by the compiler
- B.It avoids copying and keeps the real derived type, so what() and extra fields work
- C.It makes the exception non-fatal
- D.It lets you modify the thrown object
Answer & explanation
Correct answer: It avoids copying and keeps the real derived type, so what() and extra fields work
Catching by value copies the object and can slice a derived exception down to the base class.
Can you get the rest right without peeking?
Take the timed Quiz: Exception Handling in C++ quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →