error handling when opening files

Alex Burke alexjeffburke at gmail.com
Wed Jul 9 15:54:56 EDT 2014


> If that's what you're expecting, then your message is wrong, because
> you say "file never opened" - but you possibly DID open it, and maybe
> read something from it. The choice between the two forms should be
> based on whether you want to distinguish between errors on opening and
> errors on reading, or conflate them as "file unreadable". There are
> times and places for each style.

Yeah, got you - most of the responses echoed that it comes down to what
the error situations are and whether they genuinely can or cannot be dealt
with in the same way.

In the case where you do want to handle the cases differently (i.e. it was
there but oh my the contents turned out to be garbage) it does make me
wonder how you deals with that without ending up with nested try/catch - but
perhaps that would be time to use functions to make it read better.

Thanks!



More information about the Python-list mailing list