I have some code which will make a requests.get()
call, which may fail in various ways. I want to catch requests
exceptions, but do not care about why the call failed.
I would like to avoid code like
try:
r = requests.get(url)
except:
pass
because it will possible catch exceptions which are not requests
related (in the case above this would hardly be the case but if there was some more code it would be possible).
requests
exceptions are documented but I would prefer not to list all of them. Is there a way to catch them all, some kind of wildcard on requests
exceptions? (and more generally - for exceptions provided by a module)
I could also go for something like
try:
r = requests.get(url)
except Exception as e:
print(e)
but I would like to avoid analyzing e
to filter out requests
exceptions.
Note: this is not a duplicate of a question on handling all but one exception - I am targeting a whole class of related exceptions (and allow for a crash if something else raises an exception, which in my case would be a bug)