ProgrammingHardGATE CS · Product-company placement

A service catches errors with `except Exception:` around its main loop. Which of the following will NOT be caught by that handler?

  1. A. ZeroDivisionError from a bad calculation
  2. B. StopIteration raised manually inside the loop body
  3. C. UnicodeDecodeError while reading a file
  4. D. KeyboardInterrupt raised when the user presses Ctrl+C

Correct answer: D. KeyboardInterrupt raised when the user presses Ctrl+C

KeyboardInterrupt, SystemExit and GeneratorExit derive from BaseException, not Exception, precisely so that a broad `except Exception` does not swallow them. UnicodeDecodeError is a ValueError subclass, and StopIteration is an ordinary Exception.

More Python Programming questions

Exams that ask this topic