Python 运行时捕获 Warning

来源:互联网 发布:程序员 转行 编辑:程序博客网 时间:2024/05/21 20:28

>>> import warnings>>> >>> warnings.filterwarnings('error')>>> >>> try:...     warnings.warn(Warning())... except Warning:...     print 'Warning was raised as an exception!'... Warning was raised as an exception!




参考资料:

1、http://stackoverflow.com/questions/15933741/how-do-i-catch-a-warning-in-python-like-its-an-exception-not-just-for-testing

2、https://docs.python.org/2/library/warnings.html


0 0
原创粉丝点击