I'm writing a very basic Python script based on a
result = func(*some_args):
if (result != True):
def func1(arg1 , arg2):
return False #Or some err_val
func1(val1 , val2)
if __name__ == "__main__":
result = main()
if (result == err_val1):
# Do something. Maybe print. Maybe call some function.
I guess, what you really want is a universal exception catcher, that would catch and return the exception of any wrapped function. You can easily do it this way.
def return_exception(func): def wrapper(*args, **kwargs): try: return func(*args, **kwargs) except Exception as e: return e return wrapper
In : @return_exception ...: def div(a, b): ...: return a / b ...: In : div(1, 0) Out: ZeroDivisionError('division by zero')
So then you can process the return exception object the way you want, though it's pretty hard to say why you need that.