Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #15797 > unrolled thread
| Started by | Dan Sommers <dan@tombstonezero.net> |
|---|---|
| First post | 2011-11-17 01:07 +0000 |
| Last post | 2011-11-17 01:07 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: try - except. How to identify errors unknown in advance? Dan Sommers <dan@tombstonezero.net> - 2011-11-17 01:07 +0000
| From | Dan Sommers <dan@tombstonezero.net> |
|---|---|
| Date | 2011-11-17 01:07 +0000 |
| Subject | Re: try - except. How to identify errors unknown in advance? |
| Message-ID | <mailman.2789.1321492072.27778.python-list@python.org> |
On Wed, 16 Nov 2011 17:57:27 +0100, Frederic Rentsch wrote:
> I'd like to log MySQL errors. If I do:
>
> try: (command)
> except MySQLdb.OperationalError, e: print e
>
> I may get something like:
>
> (1136, "Column count doesn't match value count at row 1")
>
> If I don't know in advance which error to expect, but on the contrary
> want to find out which error occurred, I can catch any error by omitting
> the name:
>
> except: (handle)
>
> But now I don't have access to the error message 'e'. I'm sure there's a
> way and it's probably ridiculously simple.
"except" catches any exception that inherits from its argument, and all
MySQL exceptions inherit from MySQLError, so something like this will
catch only MySQL exceptions and nothing else:
try: (command)
except MySQLdb.MySQLError as e:
print(e)
Dan
Back to top | Article view | comp.lang.python
csiph-web