try... except with unknown error types
Chris Torek
nospam at torek.net
Wed Aug 31 17:01:34 EDT 2011
In article <mailman.286.1313956388.27778.python-list at python.org>,
Terry Reedy <tjreedy at udel.edu> wrote:
>I would expect that catching socket.error (or even IOError) should catch
>all of those.
>
>"exception socket.error
>A subclass of IOError ...
Except that, as Steven D'Aprano almost noted elsethread, it isn't
(a subclass of IOError -- the note was that it is not a subclass
of EnvironmentError). In 2.x anyway:
>>> import socket
>>> isinstance(socket.error, IOError)
False
>>> isinstance(socket.error, EnvironmentError)
False
>>>
(I just catch socket.error directly for this case.)
(I have also never been sure whether something is going to raise
an IOError or an OSError for various OS-related read or write
operation failures -- such as exceeding a resource limit, for
instance -- so most places that do I/O operations on OS files, I
catch both. Still, it sure would be nice to have a static analysis
tool that could answer questions about potential exceptions. :-) )
--
In-Real-Life: Chris Torek, Wind River Systems
Intel require I note that my opinions are not those of WRS or Intel
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: gmail (figure it out) http://web.torek.net/torek/index.html
More information about the Python-list
mailing list