Is it better to use an exception or a return code in Python?

后端 未结 6 2150
执念已碎
执念已碎 2020-12-13 06:08

You may know this recommendation from Microsoft about the use of exceptions in .NET:

Performance Considerations

...

Throw exc

6条回答
  •  有刺的猬
    2020-12-13 06:42

    The pythonic thing to do is to raise and handle exceptions. The excellent book "Python in a nutshell" discusses this in 'Error-Checking Strategies' in Chapter 6.

    The book discusses EAFP ("it's easier to ask forgiveness than permission") vs. LBYL ("look before you leap").

    So to answer your question:

    No, I would not recommend the same for python code. I suggest you read chapter 6 of Python in a nutshell.

提交回复
热议问题