简体   繁体   English

er在这里代表什么?

[英]what does the er here stands for?

try: 
    os.execvp('sqlite3', args) 
except OSError, er: 
    if er.errno == 2: #file not found 
        raise OSError, _("sqlite3 executable not found. Is it installed?") 
    else: 
        raise 
except: 
    raise 

In the above code, the except statement catches the OSError but what does the er variable stand for? 在上面的代码中, except语句捕获了OSError但是er变量代表什么?

EDIT: this one only excepts OSError ; 编辑:这只OSError is there a way to except any error and get the exception object for it? 有没有办法排除任何错误并为其获取异常对象?

As others have said, er is the instantiated form of the exception, OSError . 正如其他人所说, er是异常的实例化形式OSError

If it's helpful, here's an alternative, somewhat more explicit syntax, using the as keyword: 如果有帮助,请使用as关键字,这是另一种更明确的语法:

try: 
    os.execvp('sqlite3', args) 
except OSError as er: 
    if er.errno == 2: #file not found 
        raise OSError(_("sqlite3 executable not found. Is it installed?"))
    else: 
        raise 
except: 
        raise 

Which, to me, says that er will be an OSError . 其中,对我说, er将是一个OSError

As as er syntax was added in Python 2.6, by the way. 作为as er语法在Python 2.6添加了附加的方式。

er是被except子句捕获的实际异常对象。

er是异常对象本身。

看起来er是一个异常对象(OSError类型也看起来包含错误。ER可能代表错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM