ProgrammingVery hardGATE CS · TCS NQT Prime · Product Company SDE

Which statement correctly describes the typical cost of exceptions in C++?

  1. A. Throwing and catching an exception is comparatively expensive (stack unwinding, type matching), so exceptions should signal truly exceptional conditions, not routine control flow
  2. B. A try block imposes runtime overhead on the non-throwing path equal to an actual throw
  3. C. Catching an exception by value never risks any data loss
  4. D. Exceptions are always faster than returning an error code

Correct answer: A. Throwing and catching an exception is comparatively expensive (stack unwinding, type matching), so exceptions should signal truly exceptional conditions, not routine control flow

Modern "zero-cost" exception implementations add essentially no overhead to code that never throws, but actually throwing and unwinding is relatively slow, so exceptions are best reserved for rare, truly exceptional situations.

More OOP with C++ and Java questions

Exams that ask this topic