[Python-ideas] Improving Catching Exceptions
Sven R. Kunze
srkunze at mail.de
Fri Jun 23 10:20:28 EDT 2017
On 23.06.2017 03:02, Cameron Simpson wrote:
>
>> How about something like this?
>>
>> try:
>> val = bah[5]
>> except IndexError:
>> # handle your expected exception here
>> else:
>> foo(val)
>
> That is the kind of refactor to which I alluded in the paragraph
> above. Doing that a lot tends to obscure the core logic of the code,
> hence the desire for something more succinct requiring less internal
> code fiddling.
And depending on how complex bha.__getitem__ is, it can raise IndexError
unintentionally as well. So, rewriting the outer code doesn't even help
then. :-(
Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170623/415402c1/attachment.html>
More information about the Python-ideas
mailing list