任何代码执行前都需要考虑代码bug,当出现错误信息时需要展示其错误信息

通过try 方式

代码一

def f1():
    result = 123
    int('asdf')                 #故意设置一个错误的代码源
    return result

def run():
    try:
        ret = f1()
        print(ret)
    except Exception as e:
        print(e)     
run()
View Code

相关文章:

  • 2021-11-21
  • 2022-02-03
  • 2021-11-26
  • 2021-11-10
  • 2021-08-18
  • 2021-10-28
  • 2021-06-27
  • 2022-12-23
猜你喜欢
  • 2021-11-20
  • 2022-02-12
  • 2021-08-18
  • 2021-08-05
  • 2021-09-07
  • 2021-10-15
  • 2022-12-23
相关资源
相似解决方案