开发者

Need help understanding this python error return (Google search doesn't help)

开发者 https://www.devze.com 2023-03-07 03:23 出处:网络
In python code. When you see a negative in front开发者_JAVA技巧 of a Error Flag, what does it mean?

In python code. When you see a negative in front开发者_JAVA技巧 of a Error Flag, what does it mean?

return -errno.EACCES


That's a C style error return. A practice that is popular is to return a meaningful non-negative result of the function on success or a negative error code on failure.

In this case, the error EACCES means that permision was denied.

(See also this question)


It means negation. errno.EACCES (permission denied) is the number 13 (positive). The author of that code had a convention where he wanted the error number to be negative to be interpreted by their code later.

Presumably, he has a reason for adopting this convention. E.g., the function returns non-negative integers on non-errors that are used later on in the program.


The author may has restricted error code to negative value in order to be able to return various (positive) success values.

The convention seems to be used by some people:
http://www.google.com/codesearch?hl=en&lr=&q=%22return+-errno%22+lang%3Apython&sbtn=Search

0

精彩评论

暂无评论...
验证码 换一张
取 消