python异常抛出
本帖最后由 tomer 于 2014-11-02 21:01 编辑#cat file
def doplus(arg1,arg2):
if type(arg1)==type(1) and type(arg2)==type(1):
return arg1+arg2
else:
raise TypeError("Paramete isnot correct!")
return False
print(doplus("a","r"))
# python file
Traceback (most recent call last):
File "file", line 7, in <module>
print(doplus("a","r"))
File "file", line 5, in doplus
raise TypeError("Paramete isnot correct!")
TypeError: Paramete isnot correct!
假如参数不是整型,我只想让输出为:
TypeError: Paramete isnot correct!或
Paramete isnot correct!
其它的错误不要显示,该怎么办?
#cat file
def doplus(arg1,arg2):
if type(arg1)==type(1) and type(arg2)==type(1):
return arg1+arg2
else:
print "TypeError 'Paramete isnot correct!'"
return False
print(doplus("a","r"))
:lol bikong0411 发表于 2014-11-03 09:25 static/image/common/back.gif
#cat file
def doplus(arg1,arg2):
if type(arg1)==type(1) and type(arg2)==type(1):
你笑啥,兄弟 回复 3# tomer
就是说你要自己输出干脆自己print算了 回复 4# bikong0411
对的,就是这样的
页:
[1]