我可以在python中对exception.errno进行假设吗?
我知道,我可以用另一种方式来解决这个问题,但我希望这个问题无论如何都会很有趣我可以在python中对exception.errno进行假设吗?,python,exception-handling,Python,Exception Handling,我知道,我可以用另一种方式来解决这个问题,但我希望这个问题无论如何都会很有趣 def try_me: try: do_something() return 0 # can it be confused with an error? except some_external_module.defined_exception as e: return e.errno except: return -1 换句话说
def try_me:
try:
do_something()
return 0 # can it be confused with an error?
except some_external_module.defined_exception as e:
return e.errno
except:
return -1
换句话说,是否有任何规则或约定说错误数应严格为正?为什么这两种方式都有关系?有一种约定,0表示“无错误”,任何非零整数(正或负)表示“此代码发生了一些错误”,但Python中的约定是使用类(对象)作为例外,不是整数和错误表。谢谢大家,在这里找到了一些相关信息: