Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #88786
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!goblin1!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <davea@davea.name> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.012 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'python3': 0.07; 'pavel': 0.09; 'try:': 0.09; 'python': 0.11; 'def': 0.12; 'argument:': 0.16; 'behaviour.': 0.16; 'block.': 0.16; 'exceptions,': 0.16; 'surprising': 0.16; 'think?': 0.16; 'tuple': 0.16; 'valueerror': 0.16; 'do,': 0.16; 'wrote:': 0.18; 'print': 0.22; 'installation': 0.23; 'header:User-Agent:1': 0.23; 'header:In-Reply-To:1': 0.27; 'feature': 0.29; 'am,': 0.29; 'exceptions': 0.31; 'skip:c 30': 0.32; 'noticed': 0.34; 'subject:with': 0.35; 'except': 0.35; 'method': 0.36; 'hi,': 0.36; 'list.': 0.37; 'e.g.': 0.38; 'to:addr :python-list': 0.38; 'to:addr:python.org': 0.39; 'catch': 0.60; 'more': 0.64; 'charset:windows-1252': 0.65; 'believe': 0.68; 'received:74.208': 0.68; '2.7.': 0.84; 'subject:..': 0.84 |
| Date | Fri, 10 Apr 2015 16:27:51 -0400 |
| From | Dave Angel <davea@davea.name> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.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> |
| In-Reply-To | <64a75c32-e0ab-4ce0-9373-358c2669fe6e@googlegroups.com> |
| Content-Type | text/plain; charset=windows-1252; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Provags-ID | V03:K0:LJWnIglkRgU1/OwTJ2NhJnu4GkJMmB7g7hjgPNcOqeS49YdKJTP v38H6SD9oyDJqWLyT4lY4JYHx/lMzaUookeI1iftB8vvAKlD5/Pf3pHbyGBla+A21NDCw+w pVBqCNwYOLZtUXXtCLC01ohtd9HI9BozH76VmysQkn3uVDZH7LWKczL+rBliKtPOipSsiaR tKtiHRZA7ebNaXLJs7lHA== |
| X-UI-Out-Filterresults | notjunk:1; |
| 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.208.1428697681.12925.python-list@python.org> (permalink) |
| Lines | 51 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1428697681 news.xs4all.nl 2951 [2001:888:2000:d::a6]:45928 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:88786 |
Show key headers only | View raw
On 04/10/2015 04:48 AM, Pavel S wrote: > Hi, > > I noticed interesting behaviour. Since I don't have python3 installation here, I tested that on Python 2.7. > > Well known feature is that try..except block can catch multiple exceptions listed in a tuple: > > > exceptions = ( TypeError, ValueError ) > > try: > a, b = None > except exceptions, e: > print 'Catched error:', e > > > However when exceptions=(), then try..except block behaves as no try..except block. > > > exceptions = () > > try: > a, b = None # <--- the error will not be catched > except exceptions, e: > print 'Catched error:', e > > > I found use case for it, e.g. when I want to have a method with 'exceptions' argument: > > > def catch_exceptions(exceptions=()): > try: > do_something() > except exceptions: > do_something_else() > > > catch_exceptions() # catches nothing > catch_exceptions((TypeError,)) # catches TypeError > > > I believe that behaviour is not documented. What you think? > It's no more surprising than a for loop over an empty tuple or empty list. There's nothing to do, so you do nothing. -- DaveA
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