Dec-21-2018, 08:29 AM
(This post was last modified: Dec-21-2018, 08:30 AM by Gribouillis.)
Skaperen Wrote:what if i wanted to specifically handle KeyboardInterrupt in the code that calls this code, and the KeyboardInterrupt happens during the handling of NotADirectoryErrorIt doesn't prevent you from catching KeyboardInterrupt.
import os import time try: try: names = sorted(os.listdir('foo.txt')) except NotADirectoryError: time.sleep(2) except KeyboardInterrupt as exc: print("Hello, I caught KeyboardInterrupt!")