# 触发异常def temp_convert(var): try: return int(var) except ValueError as Argument: print ("参数没有包含数字%s"%Argument)# 调用函数temp_convert("xyz")# 以10为基数的int()的无效文字:“xyz”----------------------------------------------------------------------------# raise语法#raise [Exception [, args [, traceback]]]# 语句中 Exception 是异常的类型,args 是自已提供的异常参数。class Networkerror(RuntimeError): def __init__(self, arg): self.args = argtry: raise Networkerror("Bad hostname")except Networkerror as e: print(e.args)



