Re: Simple way of handling errors

2009-05-07 Thread Matt Nordhoff
Steven D'Aprano wrote: > On Wed, 06 May 2009 20:21:38 -0700, TomF wrote: > >>> The only reason you would bother going to the time and effort of >>> catching the error, printing your own error message, and then exiting, >>> is if you explicitly want to hide the traceback from the user. >> Well, to

Re: Simple way of handling errors

2009-05-07 Thread TomF
On 2009-05-07 01:01:57 -0700, Peter Otten <__pete...@web.de> said: TomF wrote: As a relative newcomer to Python, I like it a lot but I'm dismayed at the difficulty of handling simple errors. In Perl if you want to anticipate a file-not-found error you can simply do: open($file) or die("open

Re: Simple way of handling errors

2009-05-07 Thread Steven D'Aprano
On Wed, 06 May 2009 20:21:38 -0700, TomF wrote: >> The only reason you would bother going to the time and effort of >> catching the error, printing your own error message, and then exiting, >> is if you explicitly want to hide the traceback from the user. > > Well, to me, exposing the user to suc

Re: Simple way of handling errors

2009-05-07 Thread Stephen Hansen
> If it fails, you get both a straight-forward error message and a useful > traceback: > > Traceback (most recent call last): > File "", line 1, in > IOError: [Errno 2] No such file or directory: 'foomanchu' > > > The only reason you would bother going to the time and effort of catching > the err

Re: Simple way of handling errors

2009-05-07 Thread Peter Otten
TomF wrote: > As a relative newcomer to Python, I like it a lot but I'm dismayed at > the difficulty of handling simple errors. In Perl if you want to > anticipate a file-not-found error you can simply do: > > open($file) or die("open($file): $!"); > > and you get an intelligible error message

Re: Simple way of handling errors

2009-05-06 Thread TomF
On 2009-05-06 19:41:29 -0700, Steven D'Aprano said: On Wed, 06 May 2009 16:40:19 -0700, TomF wrote: As a relative newcomer to Python, I like it a lot but I'm dismayed at the difficulty of handling simple errors. In Perl if you want to anticipate a file-not-found error you can simply do: op

Re: Simple way of handling errors

2009-05-06 Thread Steven D'Aprano
On Wed, 06 May 2009 16:40:19 -0700, TomF wrote: > As a relative newcomer to Python, I like it a lot but I'm dismayed at > the difficulty of handling simple errors. In Perl if you want to > anticipate a file-not-found error you can simply do: > > open($file) or die("open($file): $!"); > > and y

Simple way of handling errors

2009-05-06 Thread TomF
As a relative newcomer to Python, I like it a lot but I'm dismayed at the difficulty of handling simple errors. In Perl if you want to anticipate a file-not-found error you can simply do: open($file) or die("open($file): $!"); and you get an intelligible error message. In Python, to get the