Python: Catch Multiple Exceptions in One Line
Introduction In this article we’re going to be taking a look at the try/except clause, and specifically how you can catch multiple exceptions in a single line, as well as how to use the suppress() method. Both of these techniques will help you in writing more accessible and versatile code that adheres to DRY (don’t repeat yourself) principles. Let’s start by looking at the problem: try: do_the_thing() except TypeError as e: do_the_other_thing() except KeyError as e: do_the_other_thing() except IndexError as […]
Read more