Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #95154
| References | <48587161-1bd6-47e4-b2c9-7a37c60a59e5@googlegroups.com> <mailman.1286.1438908366.3674.python-list@python.org> <c0684935-c807-4d98-9a04-8c2f7986169d@googlegroups.com> |
|---|---|
| Date | 2015-08-08 12:44 +1000 |
| Subject | Re: except block isn't catching exception |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1325.1439001880.3674.python-list@python.org> (permalink) |
On Sat, Aug 8, 2015 at 3:16 AM, <sohcahtoa82@gmail.com> wrote: > > Though I still doesn't understand why the exception isn't caught when I'm explicitly trying to catch it. I even tried changing the try/except block to this: > > try: > connection, _ = sock.accept() > except KeyboardInterrupt: > print 'KeyboardInterrupt caught!' > except socket.timeout: > print 'Socket timeout caught!' > except: > print 'other exception caught!' > finally: > print 'finally!' > > The result prints: > > Interrupting main > main interrupted! > finally! The exception isn't happening inside sock.accept(), as I explained. So you can't catch it there. ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
except block isn't catching exception sohcahtoa82@gmail.com - 2015-08-06 17:34 -0700
Re: except block isn't catching exception Chris Angelico <rosuav@gmail.com> - 2015-08-07 10:46 +1000
Re: except block isn't catching exception sohcahtoa82@gmail.com - 2015-08-07 10:16 -0700
Re: except block isn't catching exception Chris Angelico <rosuav@gmail.com> - 2015-08-08 12:44 +1000
Re: except block isn't catching exception Ian Kelly <ian.g.kelly@gmail.com> - 2015-08-08 00:56 -0600
Re: except block isn't catching exception Chris Angelico <rosuav@gmail.com> - 2015-08-08 17:08 +1000
csiph-web