What I was thinking was an if: ... else: ... inside the except: block, as seen here. You make a good point about the requests.exceptions.RequestException error being more generic than HTTPError and ConnectionError, but it turns out that HTTPError and ConnectionError both inherit from RequestException, so we can use a single except: clause to handle all of them.
Also, when we use raise in an except: block without specifying what exception to raise, it will just re-raise whatever exception the except: block caught, which I think is desirable behavior so we don't lose information by raising a generic exceptio instead of the specific exception that actually happened.
What I was thinking was an
if: ... else: ...
inside theexcept:
block, as seen here. You make a good point about therequests.exceptions.RequestException
error being more generic thanHTTPError
andConnectionError
, but it turns out thatHTTPError
andConnectionError
both inherit fromRequestException
, so we can use a singleexcept:
clause to handle all of them.Also, when we use
raise
in anexcept:
block without specifying what exception to raise, it will just re-raise whatever exception theexcept:
block caught, which I think is desirable behavior so we don't lose information by raising a generic exceptio instead of the specific exception that actually happened.