我有两个功能。函数“main”调用函数“submin”submin“函数包含try catch块并返回一些值。
如果“submin”成功执行,那么它将返回一些值,我将直接显示给最终用户。
如果我有异常,我必须准备一条用户友好的消息并打印出来。但是要做到这一点,我需要知道返回的值是否异常。
如何检查异常或有效结果中返回的值?
Here is my pseudo code:
def submain():
try:
result = call to external API
return result
excepion, e:
_logger(e)
def main(value):
for x in value:
submain()
# if return is exception then break loop and give msg to end user.
如果你想在函数main中处理(try catch)异常,那么我认为应该从函数submain及其上下文抛出它。 如果你吞下了子主函数中的异常,没有一些技巧,主函数就不可能知道这一点。在
相关问题 更多 >
编程相关推荐