szs 发表于 2018-8-6 12:33:14

python 异常

  最长用到的异常处理的形式:
  try:
  正常的操作
  except:
  发生异常,执行这块代码
  else:
  如果没有异常执行这块代码
  finally:
  不管如何,最后一定要执行的代码
  try:
  10/0
  except Exception as e:
  print ('出错了:', e)
  else:
  print('ok')
  finally:
  print('finally')
  出错了: division by zero
  finally
  try:
  10/5
  except Exception as e:
  print ('出错了:', e)
  else:
  print('ok')
  finally:
  print('finally')
  ok
  finally
页: [1]
查看完整版本: python 异常