我有两个功能
bar()
和
foo()
.
巴尔)
执行
英尺()
.
def foo():
try:
num = int( input("need an Integer") )
except ValueError:
print("input invalid")
def bar():
foo()
当我跑步的时候
巴尔)
输入一个非整数值,我应该得到
"input invalid"
消息。但是,如果我想自定义此错误消息
“输入无效”
在里面
巴尔)
没有
修改
英尺()
.
我该怎么办?
我试过以下方法,但这不起作用。
def foo():
try:
num = int( input("need an Integer") )
except ValueError:
print("input invalid")
def bar():
try:
foo()
except Exception as result: <-- this does not capture the error in foo()
print("my customized error message")
期望输出为:
"my customized error message"
而不是
“输入无效”
(但如果我能同时输出这两条消息,这是可以接受的)