如何屏蔽程序异常日志
def do_plus(first,second):
for param in (first,second):
if(type(param)!=type("")) and (type(param)!=type(1)):
raise TypeError("this funcion needs a string or an interger")
return first+second
a=do_plus(,3)
print(a)
# python file
Traceback (most recent call last):
File "file", line 6, in ?
a=do_plus(,3)
File "file", line 4, in do_plus
raise TypeError("this funcion needs a string or an interger")
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)
File "file", line 4, in do_plus
不想让他输出,怎么办 不想看可以使用try:来捕获异常,然后自己写几句代码来输出你想要看的信息,或者不输出。
页:
[1]