标签:main error python test err stc 单元 == imp
所有的异常来自 BaseException
记录错误 :
# err_logging.py
import logging
def foo(s):
return 10 / int(s)
def bar(s):
return foo(s) * 2
def main():
try:
bar(‘0‘)
except Exception as e:
logging.exception(e)
main()
print(‘END‘)
-----------------
抛出错误给上级
# err_reraise.py
def foo(s):
n = int(s)
if n==0:
raise ValueError(‘invalid value: %s‘ % s)
return 10 / n
def bar():
try:
foo(‘0‘)
except ValueError as e:
print(‘ValueError!‘)
raise
bar()
------------------------
unittest.TestCase内置了许多方法
标签:main error python test err stc 单元 == imp
原文地址:http://www.cnblogs.com/smartwen666/p/7911340.html