Why does except Exception: not catch a KeyboardInterrupt raised by pressing Ctrl+C?
Correct answer C. KeyboardInterrupt inherits from BaseException, not from Exception
Explanation
BaseException is the root of the exception hierarchy. KeyboardInterrupt, SystemExit and GeneratorExit derive directly from it so that generic except Exception handlers do not accidentally swallow requests to stop the program. A bare except: or except BaseException: would catch it.
Answer checked How we write and check questions
Discussion