自定义异常的两种方式 一、抛出异常 def greet(name, city): if not isinstance(name, str): raise TypeError("Name must be str") if not isinstance(city, str): raise TypeError("Age must be str") print("My name is %s, and I come from" % (name, city)) greet(1, 2) 二、自定义异常(一) 调用父类Exception的__init