Let's say I need to use a library to access the API of a third-party resource..
from thirdparty import Client
client = Client(credentials)
And in our case, the credentials are incorrect, respectively, an error occurs inside the library due to the fact that the login request was unsuccessful. Application closes due to an error.
Let's say you can use Try-Except, but it does not look very effective
try:
client = Client(credentials)
except:
# do something with error
If we need to do a lot of different actions, then wrap each one in a Try-Except? Then you get something like:
try:
friends= client.get_friends()
except:
# do something with error
try:
for friend in friends:
info = client.send_message(friend, "My message")
except:
# do something with error
Any ideas how to handle this?