try..except with empty exceptions
steve+comp.lang.python at pearwood.info
Sat Apr 11 03:42:37 CEST 2015
On Sat, 11 Apr 2015 05:31 am, sohcahtoa82 at gmail.com 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.
except This, That:
# Implicitly a tuple of two exceptions.
# Implicitly an empty tuple.
I'm not surprised that it fails, especially in Python 2 before
the "except ... as err" syntax was available, but the OP is not alone in
thinking that an empty tuple should catch everything.
I'm fairly dubious about catching everything, that sounds like a good way to
hide bugs, but if you need to catch everything, using Exception is the
usual way to do it.
More information about the Python-list