You could change sys.excepthook
if you really don't want to use a try/except
.
import sys
def my_except_hook(exctype, value, traceback):
if exctype == KeyboardInterrupt:
print "Handler code goes here"
else:
sys.__excepthook__(exctype, value, traceback)
sys.excepthook = my_except_hook
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…