异常介绍

<1>异常简介

看如下示例:

1
2
3
print '-----test--1---'
open('123.txt','r')
print '-----test--2---'

运行结果:

1
2
3
4
5
-----test--1---
Traceback (most recent call last):
  File "D:\Python_Workspace\HelloWorld\aa\Hello.py", line 2, in <module>
    open('123.txt','r')
FileNotFoundError: [Errno 2] No such file or directory: '123.txt'

说明:

打开一个不存在的文件123.txt,当找不到123.txt 文件时,就会抛出给我们一个IOError类型的错误,No such file or directory:123.txt (没有123.txt这样的文件或目录)

异常:

当Python检测到一个错误时,解释器就无法继续执行了,反而出现了一些错误的提示,这就是所谓的"异常"

posted on   LoaderMan  阅读(166)  评论(0编辑  收藏  举报

< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8

导航

统计

喜欢请打赏

扫描二维码打赏

了解更多

点击右上角即可分享
微信分享提示