Exception as the primary error handling mechanism?

Benjamin Kaplan benjamin.kaplan at case.edu
Wed Jan 6 07:54:17 CET 2010


On Tue, Jan 5, 2010 at 8:45 PM, Phlip <phlip2005 at gmail.com> wrote:
>
> Here's a super easy example:
>
>  { 42: 'forty two' }.get(41, None)
>
> Because I can supply a default, I can decide what is an error and what
> is .
>
> Now the equivalent in a language that does not enjoy this false "Zen":
>
>  { 42: 'forty two' }[41]  # returns None
>  { 42: 'forty two' }.fetch(41, None)  # ibid
>  { 42: 'forty two' }.fetch(41)  # raises an exception

Here's another super easy example.

Should

{42 : 'forty two'}[41]

be treated the same as

{41: None}[41] ?

In cases where None is a valid result, you can't use it to signal failure.



More information about the Python-list mailing list