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