try..except with empty exceptions

Rustom Mody rustompmody at gmail.com
Sat Apr 11 00:39:24 EDT 2015


On Saturday, April 11, 2015 at 9:47:36 AM UTC+5:30, Rustom Mody wrote:
> On Saturday, April 11, 2015 at 9:17:16 AM UTC+5:30, Dave Angel wrote:
> > On 04/10/2015 10:38 PM, Rustom Mody wrote:
> > > On Saturday, April 11, 2015 at 7:53:31 AM UTC+5:30, Dave Angel wrote:
> > >> On 04/10/2015 09:42 PM, Steven D'Aprano wrote:
> > >>> On Sat, 11 Apr 2015 05:31 am, sohcahtoa82 wrote:
> > >>>
> > >>>> It isn't document because it is expected.  Why would the exception get
> > >>>> caught if you're not writing code to catch it?  If you write a function
> > >>>> and pass it a tuple of exceptions to catch, I'm not sure why you would
> > >>>> expect it to catch an exception not in the tuple.  Just because the tuple
> > >>>> is empty doesn't mean that it should catch *everything* instead.  That
> > >>>> would be counter-intuitive.
> > >>>
> > >>> Really? I have to say, I expected it.
> > >>>
> > >>>
> > >>
> > >> I'm astounded at your expectation.  That's like saying a for loop on an
> > >> empty list ought to loop on all possible objects in the universe.
> > >
> > > To work, this analogy should also have two python syntaxes like this:
> > >
> > > "Normal" for-loop:
> > > for var in iterable:
> > >    suite
> > >
> > > "Empty" for-loop:
> > > for:
> > >    suite
> > >
> > 
> > That tells me nothing about your opinions.  What did you mean by the 
> > phrase "to work"?
> 
> Your analogy is "for loop on an empty list ought to loop on all possible
> objects in the universe"
> This seemingly works as a demo of a ridiculous expectation
> because there is only one pattern of for-loop
> for var in iterable:
> 
> In the case of exceptions we have two patterns
> except e-tuple:
> and
> except: 
> with the second having a wildly different semantics from the first

IOW:
OP is surprised that except (): is a no-op
The real surprise is that except: is valid syntax with questionable semantics



More information about the Python-list mailing list