Categories
Python Answers

How to catch multiple exceptions in one line with Python?

Spread the love

Sometimes, we want to catch multiple exceptions in one line with Python.

In this article, we’ll look at how to catch multiple exceptions in one line with Python.

How to catch multiple exceptions in one line with Python?

To catch multiple exceptions in one line with Python, we can catch multiple exceptions in 1 line.

For instance, we write

try:
    #...
except (IDontLikeYouException, YouAreBeingMeanException) as e:
    pass

to add an except block that catches the IDontLikeYouException and YouAreBeingMeanException in 1 line.

Conclusion

To catch multiple exceptions in one line with Python, we can catch multiple exceptions in 1 line.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *