I have multiple functions, which are chained together, something like this:
def first_function(params):
value = None
try:
value = some_api_call(params)
except ValueError:
print("some ValueError Message!")
if value is not None:
return value
variable = first_function(params)
def second_function(variable):
return some_other_api_call(variable)
As you can see, there is a try/except in the first function, and similar ones are in the other functions as well. Since all of those functions (more like 3-4) depend on each other and would raise an Error, if anyone of those failed, I'd have to include an AttributeError additionally to the other errors I'd want to catch, or check if the value exists, right?
Now I was thinking, is there a more pythonic way of doing this? In another post I read, it was stated that it's bad practice to check if a variable exists - which I would need to do, if I wanted to implement checks. Maybe I could raise the errors in every function and only catch them in the last one, or something similar?