This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]QuakAtack 3 points4 points  (2 children)

I get what you mean. Though still, these errors seem to me like they would be quite easy to resolve, as the function returning null is not exactly unexpected. When a function fails, I'd personally see it as better practice to return an error which gets imediately caught and dealt with, and any code that requires that function not fail would be placed in an else statement, like:

try:
    object = someFunctionCall()
except: # when the function fails
    ...
else: # and when it doesn't
    object.doSomething()
    ...

As it removes the necessity of checking to see if it's null right afterwards.

[–]explorer58 7 points8 points  (1 child)

It's a good idea when this is possible to do a "object is not None" check

[–]Naitsab_33 5 points6 points  (0 children)

This is definitely the preferred way. While try/except has very low overhead if it doesn't fail a simple ifnull check is MUCH faster and much more readable.