捕获异常:读取数据库, 改变特殊值
try:
有可能发生异常的代码
except:
pass
捕获指定异常:
try:
coding
except (异常名称):
coding
捕获所有异常
try:
coding
except Exception as e:
print(e)
# FileNotFoundError: [Errno 2] No such file or directory: 'hello.txt' io
# try:
# file = open("hello.txt", 'w+')
# print(apple)
# result = file.read()
# file.close()
#
# except Exception as e:
# # 当发生异常的时候执行
# print(e)
# print("**********")
# 模块
import os
import time
from time import sleep as sl
import keyword
sl(1)
print("hello")