如何在 Python 中捕获 TypeError 异常?
pythonserver side programmingprogramming
TypeError 是由组合错误类型的对象或使用错误类型的对象调用函数引起的。
示例
import sys try : ny = 'Statue of Liberty' my_list = [3, 4, 5, 8, 9] print my_list + ny except TypeError as e: print e print sys.exc_type
输出
can only concatenate list (not ""str") to list <type 'exceptions.TypeError'>