RE: newbie question about confusing exception handling in urllib

2013-04-12 Thread Prasad, Ramit
Steven D'Aprano wrote: > try: > main() > except Exception as err: > log(err) > print("Sorry, an unexpected error has occurred.") > print("Please contact support for assistance.") > sys.exit(-1) > > I like the traceback[0] module for logging last exception thrown. See tracebac

Re: newbie question about confusing exception handling in urllib

2013-04-09 Thread Ian Kelly
On Tue, Apr 9, 2013 at 5:41 AM, wrote: > try: > response = urllib.request.urlopen(request) > content = response.read() > except BaseException as ue: > if (isinstance(ue, socket.timeout) or (hasattr(ue, "reason") and > isinstance(ue.reason, sock

Re: newbie question about confusing exception handling in urllib

2013-04-09 Thread Chris Angelico
On Wed, Apr 10, 2013 at 1:05 AM, Steven D'Aprano wrote: > One exception to this rule (no pun intended) is that sometimes you want > to hide the details of unexpected tracebacks from your users. In that > case, it may be acceptable to wrap your application's main function in a > try block, catch an

Re: newbie question about confusing exception handling in urllib

2013-04-09 Thread Steven D'Aprano
On Tue, 09 Apr 2013 06:19:09 -0700, cabbar wrote: > How do I > handle all other exceptions, just say Exception: and handle them? I want > to silently ignore them. Please don't. That is normally poor practice, since it simply hides bugs in your code. As a general rule, you should only catch exce

Re: newbie question about confusing exception handling in urllib

2013-04-09 Thread Peter Otten
cab...@gmail.com wrote: > Ah, looks better. > > But, 2 questions: > > 1. I should also catch ConnectionResetError I am guessing. Does it need a special reaction? If so give it its own except suite. > 2. How do I handle all other exceptions, just say Exception: and handle > them? I want to sile

Re: newbie question about confusing exception handling in urllib

2013-04-09 Thread Terry Jan Reedy
On 4/9/2013 7:41 AM, cab...@gmail.com wrote: Hi, I have been using Java/Perl professionally for many years and have been trying to learn python3 recently. As my first program, I tried writing a class for a small project, and I am having really hard time understanding exception handling in url

Re: newbie question about confusing exception handling in urllib

2013-04-09 Thread cabbar
Ah, looks better. But, 2 questions: 1. I should also catch ConnectionResetError I am guessing. 2. How do I handle all other exceptions, just say Exception: and handle them? I want to silently ignore them. Thanks... On Tuesday, April 9, 2013 2:41:51 PM UTC+3, cab...@gmail.com wrote: > Hi, > >

Re: newbie question about confusing exception handling in urllib

2013-04-09 Thread Peter Otten
cab...@gmail.com wrote: > Hi, > > I have been using Java/Perl professionally for many years and have been > trying to learn python3 recently. As my first program, I tried writing a > class for a small project, and I am having really hard time understanding > exception handling in urllib and in py

newbie question about confusing exception handling in urllib

2013-04-09 Thread cabbar
Hi, I have been using Java/Perl professionally for many years and have been trying to learn python3 recently. As my first program, I tried writing a class for a small project, and I am having really hard time understanding exception handling in urllib and in python in general... Basically, what