1
下面的代码返回:Python:为什么这不会抛出异常?
TypeError: cannot concatenate 'str' and 'int' objects
为什么它不抛出异常?
while True:
try:
print "test" + 1
except ValueError:
print "You can't concatenate that different object types silly"
'ValueError'和'TypeError'不是同一个词 – Ryan
这是对你有好处,它没有运行,这是一个无限循环,如果用TypeError替换ValueError! – MYGz
将'catch ValueError:'更改为'catch TypeError:'。显然,除去'while True',除非你想看到你的错误消息重复无穷无尽。 – Kevin