Path: csiph.com!eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!bcyclone05.am1.xlned.com!bcyclone05.am1.xlned.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'modified': 0.05; 'exception.': 0.07; 'cc:addr:python-list': 0.09; 'oserror': 0.09; 'exception': 0.13; 'doesnt': 0.16; 'exceptions.': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'hangs': 0.16; 'inserting': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'received:211.29': 0.16; 'received:211.29.132': 0.16; 'received:cskk.homeip.net': 0.16; 'received:homeip.net': 0.16; 'received:optusnet.com.au': 0.16; 'received:syd.optusnet.com.au': 0.16; 'simpson': 0.16; 'specifics': 0.16; 'subject:handling': 0.16; 'sure.': 0.16; 'wrote:': 0.16; 'laura': 0.18; 'try:': 0.18; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'exceptions': 0.22; 'precise': 0.22; 'subject:problem': 0.22; 'cheers,': 0.22; 'cc:no real name:2**0': 0.22; 'this:': 0.23; 'header:In-Reply-To:1': 0.24; 'header:User- Agent:1': 0.26; 'least': 0.27; 'looks': 0.29; 'itself,': 0.29; 'prints': 0.29; 'raise': 0.29; 'print': 0.30; 'code': 0.30; 'problem': 0.33; 'raising': 0.33; 'received:com.au': 0.33; 'except': 0.34; 'handle': 0.34; 'add': 0.34; 'so,': 0.35; 'on,': 0.35; 'but': 0.36; 'instead': 0.36; 'actions': 0.36; 'subject:: ': 0.37; 'display': 0.37; 'charset:us-ascii': 0.37; 'easy': 0.60; 'press': 0.61; 'cameron': 0.66; 'received,': 0.84 Date: Fri, 25 Sep 2015 14:59:19 +1000 From: Cameron Simpson To: shiva upreti Cc: python-list@python.org Subject: Re: ConnectionError handling problem MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <4852c463-0c47-4fef-956a-c6c20f59fc0e@googlegroups.com> User-Agent: Mutt/1.5.23 (2014-03-12) References: <4852c463-0c47-4fef-956a-c6c20f59fc0e@googlegroups.com> X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.1 cv=W4DFLkik c=1 sm=1 tr=0 a=t6IGaf1l19PsElHJfDn/BA==:117 a=t6IGaf1l19PsElHJfDn/BA==:17 a=ZtCCktOnAAAA:8 a=PO7r1zJSAAAA:8 a=vrnE16BAAAAA:8 a=kj9zAlcOel0A:10 a=ff-B7xzCdYMA:10 a=pGLkceISAAAA:8 a=z4aqYrfmfO8vTf3iNmwA:9 a=CjuIK1q_8ugA:10 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1443158719 news.xs4all.nl 23773 [2001:888:2000:d::a6]:49354 X-Complaints-To: abuse@xs4all.nl X-Received-Bytes: 4360 X-Received-Body-CRC: 3101556718 Xref: csiph.com comp.lang.python:97114 On 24Sep2015 20:57, shiva upreti wrote: >Thank you Cameron. >I think the problem with my code is that it just hangs without raising any exceptions. And as mentioned by Laura above that when I press CTRL+C, it just catches that exception and prints ConnectionError which is definitely a lie in this case as you mentioned. Update it to report the _actual_ exception received. (If any.) At least then you will be sure. >As my code doesnt raise any exception by itself, instead just hangs, So, no "ConnectionError" message? >I wont be able to characterize the exceptions and handle them individually. Can you repost you code once it is modified to display the precise exception. Note that one easy way to catch all but progressively handle specific exceptions looks like this: try: ... code ... except OSError as e: print OSError received, specifics are:", e except Exception as e: print "unhandled exception:", e break and so on, inserting the exception types _above_ the final "except" as you add actions for them. Cheers, Cameron Simpson