零基础学python错误error处理详解

2025-05-13 07:51:47

1、try: print(1111) 1 / 0 print(222)except NameError as error: # except跟错误类型(系统自带) print(333, 髫潋啜缅error, type(error)) # 然后自己写的处理代码except ZeroDivisionError as error: print(444, error, type(error))except TypeError as error: print(555, error, type(error))except BaseException as error: print(666, error, type(error))

零基础学python错误error处理详解

3、print('******涯箨唁峦****可以混合判断*********')try: print(111) '1' + 1 print(222)except (NameError, ZeroDivisionError, TypeError) as e: print(333, e, type(e))except BaseException as e: print(444, e)

零基础学python错误error处理详解

5、def fn3(n): return fn2(n)try: print(111) print(fn3(0)) print(222)except BaseException as e: print(e)

零基础学python错误error处理详解

7、print('******涯箨唁峦**断言升级版*********')def dog(n): if not n: raise TypeError('我爱中国&垆杪屑丝#39;) return 1 / ndef make(): try: print(dog(0)) except TypeError as e: print(e, type(e), 111) raise etry: make()except BaseException as e: print(e, type(e), 222)print('**end**')

零基础学python错误error处理详解
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
相关推荐
  • 阅读量:61
  • 阅读量:96
  • 阅读量:76
  • 阅读量:76
  • 阅读量:63
  • 猜你喜欢