Back to blog home

Catch Multiple Exceptions In One Line Except Block

by Adam on 2016-07-21

This is my highest voted answer on Stack Overflow:


An except clause may name multiple exceptions as a parenthesized tuple, for example:

except (IDontLikeYouException, YouAreBeingMeanException) as e:

Perhaps the reason for this being my highest voted answer is that when people are doing quick or exploratory coding/programming, they need a way to push past a variety of errors.

In an ideal world maybe we'd catch exceptions separately, and do something different for each type of exception. What kind of world do we live in, though?

tags: python exception try except

Post thanked 0 time(s).

Related posts: