Skip to content

Comment on Exceptions (2003)parent

Comments

It seems to be a pattern in Python APIs to allow the caller to decide if a given function call should throw an exception when an error occurs. For example,

    a = some_dict['nonexistent_key']
would raise a KeyError, while
    a = some_dict.get('nonexistent_key', 'DEFAULT')
would return 'DEFAULT' instead.
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.