Python基础——8错误、调试和测试

捕捉错误

try:
    print('try...')
    r = 10 / int('2')
    print('result:', r)
except ValueError as e:
    print('ValueError:', e)
except ZeroDivisionError as e:
    print('ZeroDivisionError:', e)
else:
    print('no error!')
finally:
    print('finally...')
print('END')

调试

import logging

logging.baseConfig(level=logging.INFO)

logging.info(‘此处有错误’)

提示优先顺序为:DEBUG INFO WARNING ERROR四种

你可能感兴趣的:(Python基础——8错误、调试和测试)