MySQLdb module & error capturing

Franz GEIGER fgeiger at datec.at
Wed Jun 27 02:25:23 EDT 2001


Hi Paula,

if you import _mysql you can catch the exceptions like so:


import _mysql

<snip>

      try:
         customer.store().saveChanges()
      except _mysql.OperationalError, e:
         if e[0] == 1048:
            showerror("Error", "Missing some data!")
            return 0
         else:
            raise

<snip>

Hope this helps.

Regards
Franz


<paula at merns.com> wrote in message
news:mailman.993583119.2912.python-list at python.org...
> I'm a little bit of a newbie so if this belongs on another list let
> me know.
>
> I am trying to capture a _mysql.OperationalError that is returned by
> the MySQLdb module so that I can process it through error handling.
> Or even just print out the one bit (the error number and the error
> text) with out having the 5 layered traceback message showing every
> layer of my program. Sample error at bottom.
>
> I have tried looking at the MySQLdb module and I have not noted
> direct error passing back to the calling program from the C API.
>
> Anyone else know the answer?
>
> I have been looking at the traceback module but I don't know enough
> about it to really figure this out.
>
> Thanks for your help,
> Paula
>
> ****Sample Code
> >>> causeerror=decur.execute("select everything from everywhere")
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File "/usr/local/lib/python2.1/site-packages/MySQLdb.py", line 190,
> in execute    return self._query(query)
>   File "/usr/local/lib/python2.1/site-packages/MySQLdb.py", line 290,
> in _query
>     rowcount = self._BaseCursor__do_query(q)
>   File "/usr/local/lib/python2.1/site-packages/MySQLdb.py", line 235,
> in __do_query
>     db.query(q)
> _mysql.OperationalError: (1146, "Table 'ZimbuT.everywhere' doesn't
> exist")
>
>
>





More information about the Python-list mailing list