
Benjamin W. answered 02/06/21
Graduate Student and Python Developer
A good place to begin with any question about Python syntax is the Python documentation available at docs.python.org. So let's see what the documentation has to say:
Atry
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 sametry
statement. An except clause may name multiple exceptions as a parenthesized tuple...
The key here is the last line that mentions naming multiple exceptions as a parenthesized tuple. To achieve the behavior you are looking for, the exceptions need to be place into a tuple:
(IDontLikeYouException, YouAreBeingMenException)
With that in mind, the entire try/except block should look something like this:
try:
something_that_may_fail()
except (IDontLikeYouException, YouAreBeingMeanException) as ex:
say_please()