Python:为什么不抛出异常?

时间:2017-02-15 04:54:12

标签: python python-2.7 error-handling try-catch

以下代码返回:

docController.uti = @"com.yourapp.package";

为什么不抛出异常?

TypeError: cannot concatenate 'str' and 'int' objects

1 个答案:

答案 0 :(得分:2)

你可以像这样捕捉异常:

try:
    print "test" + 1
except ValueError:
    print "You can't concatenate that different object types silly"
except TypeError:
    print "TypeError and the words you want to say"