免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1928 | 回复: 1
打印 上一主题 下一主题

如何屏蔽程序异常日志 [复制链接]

论坛徽章:
3
天秤座
日期:2014-10-29 11:37:572015元宵节徽章
日期:2015-03-06 15:50:39NBA常规赛纪念章
日期:2015-05-04 22:32:03
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2014-11-04 10:51 |只看该作者 |倒序浏览

  1. def do_plus(first,second):
  2.     for param in (first,second):
  3.         if(type(param)!=type("")) and (type(param)!=type(1)):
  4.             raise TypeError("this funcion needs a string or an interger")
  5.     return first+second
  6. a=do_plus([3],3)
  7. print(a)
复制代码

  1. [root@h6 ~]# python file
  2. Traceback (most recent call last):
  3.   File "file", line 6, in ?
  4.     a=do_plus([3],3)
  5.   File "file", line 4, in do_plus
  6.     raise TypeError("this funcion needs a string or an interger")
  7. TypeError: this funcion needs a string or an interger
复制代码
使用这个do_plus函数的参数错了,但是我只想输出TypeError: this funcion needs a string or an interger
其他的如Traceback (most recent call last):
  File "file", line 6, in ?
    a=do_plus([3],3)
  File "file", line 4, in do_plus
不想让他输出,怎么办

论坛徽章:
0
2 [报告]
发表于 2014-11-06 11:37 |只看该作者
不想看可以使用try:来捕获异常,然后自己写几句代码来输出你想要看的信息,或者不输出。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP