Handling exceptions with Py2 and Py3
Random832
random832 at fastmail.com
Fri May 27 09:42:59 EDT 2016
On Fri, May 27, 2016, at 09:18, Ben Finney wrote:
> try:
> short_routine()
> except ConnectionRefusedError as exc:
> handle_connection_refused(exc)
> except OSError as exc:
> if exc.errno == errno.ECONNREFUSED:
> handle_connection_refused(exc)
But ConnectionRefusedError inherits from OSError and has errno =
ECONNREFUSED. So you can simply only have the second except block here,
and ignore the fact that Python 3 has a class hierarchy of error types.
More information about the Python-list
mailing list