1.普通异常的使用:

names = ['wt','gxb']
data = {}
try:
    # names[3]
    # data['name']
    open('b.txt')
except IndexError as e:
    print('there is not exist this key',e)
except Exception as e:
    print('I can`t find this error!!!')
else:
    print('it`s ok!!')
finally:
    print('dajkdhkaj')

2.自己触发的异常:

class MyExpection(Exception):
    def __init__(self,msg):
        self.message = msg

try:
    raise MyExpection('触发了异常')
except MyExpection as e:
    print(e)

  

相关文章:

  • 2021-09-02
  • 2021-06-28
  • 2021-06-19
  • 2021-09-09
  • 2021-12-02
  • 2021-07-04
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-28
  • 2022-12-23
  • 2022-01-29
  • 2021-11-09
  • 2021-07-29
  • 2021-08-14
相关资源
相似解决方案