# def li(list1):
# m = list1[len(list1)]
# def ll():
# list1 = [1, 6, 7, 8, 9]
# try:
# li(list1)
# except Exception as ex:
# print(ex)
# ll()
#注意:finally程序一定会执行
# def yichang():
# try:
# bc = int(input('请输入被除数:'))
# c = int(input('请输入被除数:'))
# s = bc / c
# return s
# except ValueError:
# print('请输入数字!')
# except ZeroDivisionError:
# print('除数不能为0!')
# finally:
# print('finally-----')
# print('程序结束!')
# yichang()
#自定义异常:
# class ageException(Exception):
# pass
# def doage():
# age = int(input('请输入年龄:'))
# if age > 100 or age < 0:
# raise ageException('年龄只能是大于0或者小于100的数!')
# try:
# doage()
# except ageException as ae:
# print(ae)
# except ValueError:
# print('年龄是数字,请输入数字!')
#异常
import logging
log_format = '%(asctime)s-%(levelname)s-%(message)s'
logging.basicConfig(filename='异常日志.txt',level=logging.DEBUG,format=log_format)
def yichang():
try:
bc = int(input('请输入被除数:'))
c = int(input('请输入被除数:'))
s = bc / c
return s
except ValueError:
print('请输入数字!')
except ZeroDivisionError:
print('除数不能为0!')
finally:
print('finally-----')
print('程序结束!')
yichang()
异常和日志
最新推荐文章于 2021-11-01 17:55:02 发布