异常处理

try-exception-finally

1
2
3
4
5
6
try:
XXX
exception XXX:
XXXXX
finally:
XXXX

raise

https://blog.csdn.net/qq_35541155/article/details/108809130

一般代码错误会触发特定异常

某些场景,代码没有错误,也可以人工触发特定异常,借助raise

1
2
3
4
5
6
7
8
9
10
11
12
13
try:
try:
raise ValueError(123)
except Exception as e:
print(e)
raise ValueError(456)

except Exception as e1:
print(e1)




1
2
3
123
456

Author

Lavine Hu

Posted on

2022-09-18

Updated on

2024-03-23

Licensed under

# Related Post
  1.logging
  2.python内存管理
  3.路径
  4.pandas
  5.
  6.metaclass
  7.unittest
  8.list
Comments

:D 一言句子获取中...