Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我可以在python中对exception.errno进行假设吗?_Python_Exception Handling - Fatal编程技术网

我可以在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中的约定是使用类(对象)作为例外,不是整数和错误表。谢谢大家,在这里找到了一些相关信息: