标签:python
##异常处理 #try: # pass #except Exception as ex: Exception(捕获所有错误)可以换成任何异常类型,代表只捕获指定错误, # 可以写多个except # pass ##异常类型: # # ##完整的异常代码: # try: # raise Exception(‘testeetst‘) #主动触发异常 ,Exception可以是其他异常类型 # except ValueError as ex: # print(ex) # except Exception as ex: # pass # else: # pass # finally: # pass ##自定义异常 #继承Exception类 # ##断言 #assert 1==1 相当于if else 然后抛出异常 while True: n1 = input("num1: ") n2 = input("num2: ") try: n1 = int(n1) n2 = int(n2) print(n1 + n2) except Exception as e: print(e)
标签:python
原文地址:http://lejie.blog.51cto.com/3080804/1928700