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.