On 22Jun2017 19:47, Andy Dirnberger firstname.lastname@example.org wrote:
On Jun 22, 2017, at 7:29 PM, Cameron Simpson email@example.com wrote: try: foo(bah) except IndexError as e: ... infer that there is no bah ...
Of course, it is possible that bah existed and that foo() raised an IndexError of its own. One might intend some sane handling of a missing bah but instead silently conceal the IndexError from foo() by mishandling it as a missing bah.
Naturally one can rearrange this code to call foo() outside that try/except, but that degree of control often leads to quite fiddly looking code with the core flow obscured by many tiny try/excepts. [...]
How about something like this?
try: val = bah except IndexError:
# handle your expected exception here
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.
Cheers, Cameron Simpson firstname.lastname@example.org