Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #64838
| Date | 2014-01-26 23:03 -0800 |
|---|---|
| From | Gary Herron <gary.herron@islandtraining.com> |
| Subject | Re: buggy python interpretter or am I missing something here? |
| References | <pan$57cb8$37426877$4ff183f7$e46f1ba0$1@all.net> <mailman.6018.1390799500.18130.python-list@python.org> <52e5fa05$0$29727$862e30e2@ngroups.net> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.6027.1390806238.18130.python-list@python.org> (permalink) |
On 01/26/2014 10:17 PM, me wrote: > On Sun, 26 Jan 2014 21:04:57 -0800, Gary Herron wrote: > >> Never *ever* have a bare except like that. If it gets invoked, you have >> no idea why. A simple typo like ixd instead of idx or a(idx) instead >> of a[idx] would raise an exception but give you no idea why. >> >> Do >> try: >> ... >> except Exception,e: >> print e >> at the absolute minimum. >> (Python 3 syntax would differ slightly, but the advice is the same.) >> >> Perhaps printing a traceback along with the exception would help. Add >> traceback.print_exc() > > So here's the clencher without debating the merits bare except: since a > bare catch(...) is totally acceptable in the c++ world. > > When I have except: by itself the program fails...but simply adding the > "except Exception,e: " causes the program to work correctly. Doubtful. We've been doing this kind of stuff for decades without hitting your supposed bug. Much more likely is that you've misinterpreted the results. Ii don't know how, but I'm quite confident that you have. Your contention that the raise goes back to the sys.exit() is certainly a mis-interpretation also. The re-raise of the original exception is now an uncaught exception, and the interpreter's response to an uncaught exception is to kill the program. Nearly the same result as the sys.exit(), but via a different pathway. > > To me that signifies an undefined behavior of the python specification, > or at least bad behavior of the python interpreter I'm using. If you can > syntactically use a bare except: without generating an invalid syntax > error then it should have a well defined and predictable outcome. It is well defined. Slow down a bit, rerun your two tests, show is the code *and* the results, and we'll get to the bottom of this. > > If in fact the "except Exception, e:" is what's required then a bare > except shouldn't be considered valid syntax at all, right? Bare excepts are perfectly legal valid syntax and have their uses, however it's just extremely dangerous programming to allow a simple typo (or any of an infinite number of possible errors) in your try section to masquerade as a "error in command line" (to quote your print at that point). Python's dynamic typing makes bare except extremely dangerous. In Python, unlike C, any number of typos can be syntactically correct, but meaningless, exception-raising actions at run time. Things like misspelling a variable/function name, substituting a comma for a decimal point, indexing something that is not indexable, applying a function to the wrong parameters or wrong number of parameters, ... All these are *not* syntax errors (as they would be in C), but will cause a run-time exception -- and you'd never know why with that bare except blindly catching them all and claiming "command line error". Gary Herron > > kind regards
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
buggy python interpretter or am I missing something here? me <noone@all.net> - 2014-01-27 03:42 +0000
buggy python interpretter or am I missing something here? - "TCdaemon.py" yEnc me <noone@all.net> - 2014-01-27 03:42 +0000
Re: buggy python interpretter or am I missing something here? Gary Herron <gary.herron@islandtraining.com> - 2014-01-26 21:04 -0800
Re: buggy python interpretter or am I missing something here? me <noone@all.net> - 2014-01-27 06:17 +0000
Re: buggy python interpretter or am I missing something here? Gary Herron <gary.herron@islandtraining.com> - 2014-01-26 23:03 -0800
Re: buggy python interpretter or am I missing something here? me <noone@all.net> - 2014-01-27 07:20 +0000
Re:buggy python interpretter or am I missing something here? Dave Angel <davea@davea.name> - 2014-01-27 00:36 -0500
Re:buggy python interpretter or am I missing something here? me <noone@all.net> - 2014-01-27 06:02 +0000
Re: buggy python interpretter or am I missing something here? Zachary Ware <zachary.ware+pylist@gmail.com> - 2014-01-27 00:47 -0600
Re: buggy python interpretter or am I missing something here? me <noone@all.net> - 2014-01-27 07:17 +0000
Re: buggy python interpretter or am I missing something here? Alister <alister.ware@ntlworld.com> - 2014-01-27 12:19 +0000
Re: buggy python interpretter or am I missing something here? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-27 13:48 +0000
Re: buggy python interpretter or am I missing something here? Zachary Ware <zachary.ware+pylist@gmail.com> - 2014-01-27 10:23 -0600
Re: buggy python interpretter or am I missing something here? Dan Sommers <dan@tombstonezero.net> - 2014-01-27 16:38 +0000
Re: buggy python interpretter or am I missing something here? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-27 16:45 +0000
Re: buggy python interpretter or am I missing something here? Terry Reedy <tjreedy@udel.edu> - 2014-01-27 01:21 -0500
Re: buggy python interpretter or am I missing something here? me <noone@all.net> - 2014-01-27 06:42 +0000
Re: buggy python interpretter or am I missing something here? Ethan Furman <ethan@stoneleaf.us> - 2014-01-26 23:08 -0800
Re: buggy python interpretter or am I missing something here? me <noone@all.net> - 2014-01-27 06:46 +0000
Re: buggy python interpretter or am I missing something here? Zachary Ware <zachary.ware+pylist@gmail.com> - 2014-01-27 00:55 -0600
Re: buggy python interpretter or am I missing something here? Gary Herron <gary.herron@islandtraining.com> - 2014-01-26 23:12 -0800
Re: buggy python interpretter or am I missing something here? me <noone@all.net> - 2014-01-27 07:30 +0000
Re: buggy python interpretter or am I missing something here? Peter Otten <__peter__@web.de> - 2014-01-27 09:45 +0100
Re: buggy python interpretter or am I missing something here? Ethan Furman <ethan@stoneleaf.us> - 2014-01-26 23:17 -0800
Re: buggy python interpretter or am I missing something here? me <noone@all.net> - 2014-01-27 07:44 +0000
Re: buggy python interpretter or am I missing something here? Chris Angelico <rosuav@gmail.com> - 2014-01-27 20:01 +1100
Re: buggy python interpretter or am I missing something here? me <noone@all.net> - 2014-01-27 09:32 +0000
Re: buggy python interpretter or am I missing something here? Neil Cerutti <neilc@norwich.edu> - 2014-01-27 12:56 +0000
Re: buggy python interpretter or am I missing something here? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-01-27 13:56 +0000
Re: buggy python interpretter or am I missing something here? Rick Johnson <rantingrickjohnson@gmail.com> - 2014-01-27 07:33 -0800
Re: buggy python interpretter or am I missing something here? Chris Angelico <rosuav@gmail.com> - 2014-01-28 02:53 +1100
Re: buggy python interpretter or am I missing something here? Rick Johnson <rantingrickjohnson@gmail.com> - 2014-01-27 12:22 -0800
Re: buggy python interpretter or am I missing something here? Chris Angelico <rosuav@gmail.com> - 2014-01-28 07:29 +1100
Re: buggy python interpretter or am I missing something here? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-01-27 22:25 +0000
Re: buggy python interpretter or am I missing something here? Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-01-30 18:13 +1300
Re: buggy python interpretter or am I missing something here? Terry Reedy <tjreedy@udel.edu> - 2014-01-30 04:44 -0500
Re: buggy python interpretter or am I missing something here? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-01-31 04:06 +0000
Re: buggy python interpretter or am I missing something here? Kushal Kumaran <kushal.kumaran@gmail.com> - 2014-01-31 10:37 +0530
Re: buggy python interpretter or am I missing something here? Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-01-31 19:59 +1300
Re: buggy python interpretter or am I missing something here? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-27 16:22 +0000
Re: buggy python interpretter or am I missing something here? Michael Torrie <torriem@gmail.com> - 2014-01-27 10:52 -0700
csiph-web