Skip to content

Remove unjustified uses of bare 'except' clause#148

Merged
methane merged 1 commit intoPyMySQL:masterfrom
rfk:no-bare-except
Sep 23, 2013
Merged

Remove unjustified uses of bare 'except' clause#148
methane merged 1 commit intoPyMySQL:masterfrom
rfk:no-bare-except

Conversation

@rfk
Copy link
Contributor

@rfk rfk commented Jun 3, 2013

PyMySQL contains several uses of a bare 'except' clause, like this::

try:
    do_something()
except:
    handle_error()

Using bare except is almost always a bad idea, as it captures whole-program control flow exceptions like SystemExit, KeyboardInterrupt and gevent.Timeout. This PR changes it to use the "except Exception" form, which should capture anything of interest while leaving control flow exceptions untouched.

As concrete motivation, I found this because the existing code doesn't cooperate with gevent timeouts. Code like this::

with gevent.Timeout(5):
    cursor.execute("SOME LONG RUNNING SQL STATEMENT")

Doesn't time out correctly, because PyMySQL swallows the gevent.Timeout exception and converts it into a DBAPI error. Ideally it would pass through the gevent.Timeout exception unchanged.

@methane methane merged commit f7eeaf3 into PyMySQL:master Sep 23, 2013
@methane
Copy link
Member

methane commented Sep 23, 2013

Merged. thanks.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants