petehunt/PyMySQL — Issue #94: exceptions raised incorrectly in Python 3
Author: zzzeek
Created: 2011-12-18 18:05:34+00:00
State: open

```python
import pymysql
import sys

conn = pymysql.connect(user="scott", passwd="tiger", db="test")
cursor = conn.cursor()

try:
cursor.execute("describe fake")
except:
exception = sys.exc_info()[1]
assert (exception.args[0] == 1146), exception.args[0]
```
output in Python 2:

```
classics-MacBook-Pro:sqlalchemy classic$ python test.py
classics-MacBook-Pro:sqlalchemy classic$
```

output in Python 3:

```
classics-MacBook-Pro:sqlalchemy classic$ python3 test.py
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/PyMySQL3-0.5-py3.2.egg/pymysql/cursors.py", line 112, in execute
result = self._query(query)
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/PyMySQL3-0.5-py3.2.egg/pymysql/cursors.py", line 230, in _query
conn.query(q)
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/PyMySQL3-0.5-py3.2.egg/pymysql/connections.py", line 607, in query
self._affected_rows = self._read_query_result()
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/PyMySQL3-0.5-py3.2.egg/pymysql/connections.py", line 691, in _read_query_result
result.read()
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/PyMySQL3-0.5-py3.2.egg/pymysql/connections.py", line 869, in read
self.first_packet = self.connection.read_packet()
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/PyMySQL3-0.5-py3.2.egg/pymysql/connections.py", line 686, in read_packet
packet.check_error()
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/PyMySQL3-0.5-py3.2.egg/pymysql/connections.py", line 328, in check_error
raise_mysql_exception(self.__data)
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/PyMySQL3-0.5-py3.2.egg/pymysql/err.py", line 142, in raise_mysql_exception
_check_mysql_exception(errinfo)
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/PyMySQL3-0.5-py3.2.egg/pymysql/err.py", line 135, in _check_mysql_exception
raise errorclass(errno,errorvalue)
pymysql.err.ProgrammingError: (1146, "Table 'test.fake' doesn't exist")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "test.py", line 8, in
cursor.execute("describe fake")
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/PyMySQL3-0.5-py3.2.egg/pymysql/cursors.py", line 117, in execute
self.errorhandler(self, exc, value)
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/PyMySQL3-0.5-py3.2.egg/pymysql/connections.py", line 189, in defaulterrorhandler
raise errorclass(errorvalue)
pymysql.err.ProgrammingError: (1146, "Table 'test.fake' doesn't exist")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "test.py", line 11, in
assert (exception.args[0] == 1146), exception.args[0]
AssertionError: (1146, "Table 'test.fake' doesn't exist")
classics-MacBook-Pro:sqlalchemy classic$
```