zoukankan      html  css  js  c++  java
  • Python异常记录

    1.常用异常名

    AttributeError 调用不存在的方法引发的异常。

    EOFError 遇到文件末尾引发的异常。

    ImportError 导入模块出错引发的异常。

    IndexError 列表越界引发的异常。

    IOError I/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]

  • 相关阅读:
    jsp转向
    什么是 XDoclet?
    tomcat中的几点配置说明
    mysql5问题
    POJ 3734 Blocks
    POJ 2409 Let it Bead
    HDU 1171 Big Event in HDU
    POJ 3046 Ant Counting
    HDU 2082 找单词
    POJ 1286 Necklace of Beads
  • 原文地址:https://www.cnblogs.com/rrxc/p/4213200.html
Copyright © 2011-2022 走看看