header_pic
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:

https://stackoverflow.com/questions/6470428/catch-multiple-exceptions-in-one-line-except-block

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

except (IDontLikeYouException, YouAreBeingMeanException) as e:
    pass

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: