首页 > 文章列表 > python异常模块的整理

python异常模块的整理

python异常
139 2022-08-07

1、OSError异常

OSError是操作系统相关异常。

FileNotFoundError:[Error 2] No such file or directory: 'abc.txt'

2、IndexError异常

IndexError异常是访问序列元素时,下标索引超出取值范围所引发的异常。

IndexError: list index out of range

3、ValueError异常

ValueError异常是由于传入一个无效的参数值而引发的异常。

>>> i = 'QWE
>>> print(5 / int(i))
Traceback(most recent call last):
    File"<pyshell#22>", line1, in <module>
        print(5 / int(i))
ValueError: invalid literal for int() with base 10: 'QWE'