异常
# !/usr/bin/python3# -*- coding: utf-8 -*-
# @Time : 2023/2/11 20:03
# @Author : xiongming
# @File : exception.py
# @Desc : 异常、嵌套异常、raise、异常链、assert断言、异常实现goto
try:
while True:
while True:
for i in range(10):
if i > 3:
raise
print(i)
print("被跳过了-1")
print("被跳过了-2")
print("被跳过了-3")
except:
print("到这里来了")
assert "f" == "f"
raise ValueError("值不正确")
try:
1 / 2
520 + "FishC"
except (ZeroDivisionError, TypeError) as e:
print(e)
else :
print("没有出错执行")
finally:
print("最终都会执行")
try:
try:
520 + "FishcC"
except:
print("内部异常")
1 / 0
except:
print("外部异常")
finally:
print("收尾工作")
页:
[1]