-
Notifications
You must be signed in to change notification settings - Fork 0
/
异常.py
57 lines (51 loc) · 1.18 KB
/
异常.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# 以下全是引发异常的代码
# print(1 / 0)
# print(“Hello World”)
# print("Love" + 520)
# try:
# print(1 / 0)
# print("啊?" + 10086)
# # 捕获多个指定的异常
# except (ZeroDivisionError, ValueError, TypeError) as e:
# # pass:占位符,不执行任何操作
# pass
# print("doge")
# try:
# print("正常输出" + str(10086))
# except:
# print("有异常了!")
# else:
# print("没有异常。")
# try:
# print("正常输出" + str(10086))
# # print("{}".format(1/0))
# except:
# print("有异常了!")
# else:
# print("没有异常!")
# finally:
# print("Done.")
# try:
# try:
# print("150" + 150)
# except:
# print("inner error!")
# print(1 / 0)
# except:
# print("outer error!")
# finally:
# print("Done.")
try:
s = "Hello World"
assert s != "Hello World"
except AssertionError as e:
print("已引发AssertionError")
# # 异常链
# try:
# try:
# print(1 / 0)
#
# except ZeroDivisionError as e:
# raise ValueError("啥玩意,值不对!") from e
# except ValueError as e2:
# print(e2)