class Networkerror(RuntimeError): def __init__(self, arg): self.args = arg 在你定义以上类后,你可以触发该异常,如下所示: try: raise Networkerror("Bad hostname")except Networkerror,e: print e.args