yxsailing 发表于 2017-4-21 11:06:54

Python异常

  1.常用异常名
  AttributeError调用不存在的方法引发的异常。
  EOFError遇到文件末尾引发的异常。
  ImportError导入模块出错引发的异常。
  IndexError列表越界引发的异常。
  IOErrorI/O操作引发的异常,如打开文件出错等。
  KeyError使用字典中不存在的关键字引发的异常。
  NameError使用不存在的变量名引发的异常。
  TabError语句块缩进不正确引发的异常。
  ValueError搜索列表中不存在的值引发的异常。
  ZeroDivisionError除数为零引发的异常。
2.语法
  try:
  ...guarded clause...
  except ...expression... :
  ...exception handler codee...
  finally:
  ...clean-up code...
3. raise语句
  def crossProduct(seq1, seq2):
  if not seq1 and not seq2:
  raise ValueError, "Sequence arguments must be non-empty."
  return [(x, y) for x1 in seq1 for x2 in seq2]
页: [1]
查看完整版本: Python异常