Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #88820
| Path | csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <ian@feete.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'syntax': 0.04; 'python3': 0.07; 'skip:l 60': 0.07; 'aliases': 0.09; 'modulo': 0.09; 'pgp': 0.09; 'try:': 0.09; 'python': 0.11; '(valueerror,': 0.16; '----- begin': 0.16; '-----end': 0.16; 'expect,': 0.16; 'from:addr:ian': 0.16; 'gnupg': 0.16; 'hash:': 0.16; 'parentheses:': 0.16; 'sha1': 0.16; 'skip:v 60': 0.16; 'syntaxerror:': 0.16; 'valueerror': 0.16; 'valueerror,': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'message-----': 0.19; 'skip:a 60': 0.19; '>>>': 0.22; 'example': 0.22; 'header:User-Agent:1': 0.23; 'integer': 0.24; 'pass': 0.26; 'signed': 0.27; 'header:In-Reply-To:1': 0.27; '"",': 0.31; "d'aprano": 0.31; 'division': 0.31; 'received:66.33': 0.31; 'received:66.33.216': 0.31; 'received:66.33.216.122': 0.31; 'received:dreamhost.com': 0.31; 'received:g.dreamhost.com': 0.31; 'received:hapkido.dreamhost.com': 0.31; 'skip:i 60': 0.31; 'skip:m 60': 0.31; 'steven': 0.31; 'file': 0.32; 'linux': 0.33; '(most': 0.33; 'received:66': 0.35; 'subject:with': 0.35; 'except': 0.35; 'but': 0.35; 'version:': 0.36; 'list': 0.37; 'to:addr:python- list': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'catch': 0.60; 'ian': 0.60; 'skip:* 10': 0.61; 'more': 0.64; 'charset:windows-1252': 0.65; 'mar': 0.68; 'invalid': 0.68; '2014,': 0.84; 'subject:..': 0.84; 'received:192.168.0.4': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha1; c=relaxed; d=feete.org; h=message-id :date:from:mime-version:to:subject:references:in-reply-to :content-type:content-transfer-encoding; s=feete.org; bh=Mm1pIlL CuYl7GOwtF0ILggbJRQ0=; b=bmLSQKhl9gwP9FEXp3D6vDPnLEk0hDZaDRtd8w4 rEanpFF966r30kSk3+N+SomvdI16NeQATndsZby4J3vkdtSm1LOdNPHm9x9ZXN1q H5ECB1ErCNhQ2Eq5pt8aVG/dHpEd7jGn2jzy1J5D5uBqLhk6fjkSkLwMKmIizsd0 TOe8= |
| Date | Sat, 11 Apr 2015 15:20:13 +0100 |
| From | Ian Foote <ian@feete.org> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: try..except with empty exceptions |
| References | <64a75c32-e0ab-4ce0-9373-358c2669fe6e@googlegroups.com> <785010c0-6bcc-46d7-b7e0-0ed062fabbc7@googlegroups.com> <55287c0d$0$13000$c3e8da3$5496439d@news.astraweb.com> <mailman.211.1428718999.12925.python-list@python.org> <5528c906$0$12994$c3e8da3$5496439d@news.astraweb.com> |
| In-Reply-To | <5528c906$0$12994$c3e8da3$5496439d@news.astraweb.com> |
| Content-Type | text/plain; charset=windows-1252 |
| Content-Transfer-Encoding | quoted-printable |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://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 | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.221.1428762375.12925.python-list@python.org> (permalink) |
| Lines | 61 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1428762375 news.xs4all.nl 2913 [2001:888:2000:d::a6]:48203 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:88820 |
Show key headers only | View raw
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 11/04/15 08:11, Steven D'Aprano wrote:
> But with try...except, an empty exception list means to catch
> *everything*, not nothing:
>
> try: ... except a,b,c: # catches a, b, c
>
> try: ... except a,b: # catches a, b
This example is incorrect. In python3 it is a SyntaxError:
Python 3.4.0 (default, Apr 11 2014, 13:05:11)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more
information.
>>> try:
... 1/0
... except ValueError, ZeroDivisionError:
File "<stdin>", line 3
except ValueError, ZeroDivisionError:
^
SyntaxError: invalid syntax
In python2 it aliases ValueError as ZeroDivisionError:
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more
information.
>>> try:
... 1/0
... except ValueError, ZeroDivisionError:
... pass
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
ZeroDivisionError: integer division or modulo by zero
To get the behaviour you expect, you must use parentheses:
>>> try:
... 1/0
... except (ValueError, ZeroDivisionError):
... pass
...
Regards,
Ian F
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
iQEcBAEBAgAGBQJVKS2dAAoJEODsV4MF7PWznkAH/jidWhoJ//gsvBr0ByOOOEgc
A+k8HqrkALfzrh3aEjJB3sq19oLfLcepQeFVUh77mJKOMCQdEeyJtqIz6tLc4RUa
L/nXytHygXVTb5HIARGVkPD26gqAleSb9eZUfPeSEvRHy9UbFS7SMmOdkApheDX3
Vq8TOa8EchaYd+S89y9eepZAhGC7n2TNwrNgp36sbHoz/hYUxFNnugP0ow9FM0Wk
MGKGh04c3Lao+6w7a0scz4YKKb8wTdYkyYwlJhEdg3q74+PwYJpkjcGucna745AZ
XlAKlDCJ9LhPgMufuGdRNskJa4TF709ec5hG9itHu1lFKrjH1iJCEU9ntX6hInU=
=zi4K
-----END PGP SIGNATURE-----
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
try..except with empty exceptions Pavel S <pavel@schon.cz> - 2015-04-10 01:48 -0700
Re: try..except with empty exceptions Chris Angelico <rosuav@gmail.com> - 2015-04-10 18:58 +1000
Re: try..except with empty exceptions sohcahtoa82@gmail.com - 2015-04-10 12:31 -0700
Re: try..except with empty exceptions Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-04-11 11:42 +1000
Re: try..except with empty exceptions Dave Angel <davea@davea.name> - 2015-04-10 22:23 -0400
Re: try..except with empty exceptions Rustom Mody <rustompmody@gmail.com> - 2015-04-10 19:38 -0700
Re: try..except with empty exceptions Dave Angel <davea@davea.name> - 2015-04-10 23:46 -0400
Re: try..except with empty exceptions Rustom Mody <rustompmody@gmail.com> - 2015-04-10 21:17 -0700
Re: try..except with empty exceptions Rustom Mody <rustompmody@gmail.com> - 2015-04-10 21:39 -0700
Re: try..except with empty exceptions Cameron Simpson <cs@zip.com.au> - 2015-04-11 19:27 +1000
Re: try..except with empty exceptions Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-04-11 21:00 +1000
Re: try..except with empty exceptions Chris Angelico <rosuav@gmail.com> - 2015-04-11 21:21 +1000
Re: try..except with empty exceptions Ian Kelly <ian.g.kelly@gmail.com> - 2015-04-11 12:49 -0600
Re: try..except with empty exceptions Chris Angelico <rosuav@gmail.com> - 2015-04-12 06:04 +1000
Re: try..except with empty exceptions Chris Angelico <rosuav@gmail.com> - 2015-04-12 06:05 +1000
Re: try..except with empty exceptions Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-04-11 17:11 +1000
Re: try..except with empty exceptions Serhiy Storchaka <storchaka@gmail.com> - 2015-04-11 11:22 +0300
Re: try..except with empty exceptions Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-04-11 20:47 +1000
Re: try..except with empty exceptions Dave Angel <davea@davea.name> - 2015-04-11 06:14 -0400
Re: try..except with empty exceptions Dave Angel <davea@davea.name> - 2015-04-11 06:24 -0400
Re: try..except with empty exceptions Ian Foote <ian@feete.org> - 2015-04-11 15:20 +0100
Re: try..except with empty exceptions Terry Reedy <tjreedy@udel.edu> - 2015-04-11 04:58 -0400
Re: try..except with empty exceptions Dave Angel <davea@davea.name> - 2015-04-10 16:27 -0400
Re: try..except with empty exceptions Rustom Mody <rustompmody@gmail.com> - 2015-04-10 18:56 -0700
csiph-web