class MyException(Exception):
    def __init__(self,error_msg):
        self.error_msg=error_msg
    def __str__(self):
        return self.error_msg
try:
    print('手动触发exception')         
    raise MyException('出错了')#手动触发了exception错误 会被except Exception捕获
except Exception as e:
    print('error:',e)

PS D:\python\py_test> python3 .\t1.py

手动触发exception
error: 出错了

print(123)

assert 1==1##若成立则执行后面的代码 反之直接报错

print(456)

 

相关文章:

  • 2021-08-12
  • 2022-12-23
  • 2021-12-23
  • 2022-03-09
  • 2021-11-12
  • 2021-07-19
  • 2022-12-23
猜你喜欢
  • 2021-09-13
  • 2021-07-12
  • 2022-12-23
  • 2022-12-23
  • 2022-01-26
  • 2022-02-11
  • 2022-12-23
相关资源
相似解决方案