这里是代码:
try:
input() # I hit Ctrl+C
except Exception as e:
print(str(e))
以下是跟踪信息:
Traceback (most recent call last):
File "C:\Users\User\Desktop\test.py", line 2, in <module>
input()
KeyboardInterrupt
except KeyboardInterrupt
捕获 Ctrl/C,你可以在下一个except
语句中处理所有其他异常。或者你想要完全不同的做法吗? - lenikBaseException
,那么所有其他的异常也应该被捕获。 - Nelewoutas e
并print(str(e))
。 - Joe DoeCtrl/C
中断你的程序。 - lenik