Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #15797
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.003 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'argument,': 0.09; 'exceptions': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'exception': 0.12; 'except:': 0.16; 'frederic': 0.16; 'omitting': 0.16; 'row': 0.16; 'wed,': 0.17; 'advance': 0.17; 'wrote:': 0.18; "doesn't": 0.23; '+0100,': 0.23; "i'm": 0.26; 'print': 0.29; 'subject:?': 0.31; 'error': 0.31; 'nov': 0.31; 'received:24': 0.32; 'to:addr:python-list': 0.32; 'header:User-Agent:1': 0.33; 'match': 0.33; 'header:X-Complaints- To:1': 0.33; 'probably': 0.34; 'try:': 0.34; 'subject:How': 0.35; 'something': 0.36; 'but': 0.37; 'received:org': 0.37; "i'd": 0.39; 'except': 0.39; "there's": 0.39; "it's": 0.39; 'subject:: ': 0.39; 'to:addr:python.org': 0.39; '2011': 0.62; 'subject:. ': 0.65; 'contrary': 0.73; 'catches': 0.84; 'ridiculously': 0.84; 'subject:try': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Dan Sommers <dan@tombstonezero.net> |
| Subject | Re: try - except. How to identify errors unknown in advance? |
| Date | Thu, 17 Nov 2011 01:07:37 +0000 (UTC) |
| References | <1321462647.2315.31.camel@hatchbox-one> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | 8bit |
| X-Gmane-NNTP-Posting-Host | 24.100.92.194 |
| User-Agent | Pan/0.133 (House of Butterflies) |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2789.1321492072.27778.python-list@python.org> (permalink) |
| Lines | 30 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1321492072 news.xs4all.nl 6915 [2001:888:2000:d::a6]:42399 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:15797 |
Show key headers only | View raw
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 comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: try - except. How to identify errors unknown in advance? Dan Sommers <dan@tombstonezero.net> - 2011-11-17 01:07 +0000
csiph-web