I know that I can do:
try:
# do something that may fail
except:
# do this if ANYTHING goes wrong
I can also do this:
From Python documentation -> 8.3 Handling Exceptions:
A
try
statement may have more than one except clause, to specify handlers for different exceptions. At most one handler will be executed. Handlers only handle exceptions that occur in the corresponding try clause, not in other handlers of the same try statement. An except clause may name multiple exceptions as a parenthesized tuple, for example:except (RuntimeError, TypeError, NameError): pass
Note that the parentheses around this tuple are required, because except
ValueError, e:
was the syntax used for what is normally written asexcept ValueError as e:
in modern Python (described below). The old syntax is still supported for backwards compatibility. This meansexcept RuntimeError, TypeError
is not equivalent toexcept (RuntimeError, TypeError):
but toexcept RuntimeError as
TypeError:
which is not what you want.