I have the following code:
import time
try:
time.sleep(3)
raise Exception('error')
except Exception or KeyboardInterrupt:
print(">>> Error or keyboard interrupt")
I want to catch either error or key board interrupt. But currently, it catches only Exception, keyboard interrupt is not handled.
- If I remove Exception and leave only Keyboard interrupt, it catches only keyboard interrupt.
- If I remove KeyboardInterrupt and leave only Exception, it catches only Exception.
Is there a way to catch both ?
tupleof exceptions.except (Exception, KeyboardInterrupt):