Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f476453

Browse files
Create kc49.md
1 parent 4d1a210 commit f476453

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

‎kc/kc49.md‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# 4-9 异常处理
2+
异常是程序运行当中,因为写程序时的疏漏、代码的安全性、值运算等,造成的错误,而影响程序正常运行。
3+
4+
一但异常产生,如果不做捕获处理,程序就会停止运行
5+
6+
python提供了强大的异常处理能力(python针对不同类型的异常定义了很多的类来处理,同样也可以自定义异常),可以准确的输出异常信
7+
8+
息,方便快速找到异常点
9+
10+
异常也不一定,都是有害的,在项目中,也可以利用异常的特点,做一些小窍门的动作
11+
12+
python中异常捕获主句为try..except..finally
13+
14+
- try 标识异常检测代码段的开始
15+
- except 捕获异常,并处理异常
16+
- finally
17+
### 代码区 1
18+
```python
19+
1 x = 'a'
20+
2
21+
3 try:
22+
4 b = x + 1
23+
5 except:
24+
6 print('出异常了')
25+
7
26+
```
27+
![4](https://user-images.githubusercontent.com/103555341/163546933-bee710b5-943e-454e-b00d-922d2b897614.jpg)
28+
```python
29+
出异常了
30+
```
31+
32+
33+
34+
35+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /