0
Q:

python decorator for error handling

def safe_run(func):

    def func_wrapper(*args, **kwargs):

        try:
           return func(*args, **kwargs)

        except Exception as e:

            print(e)
            return None

    return func_wrapper


0
def decorator_example(func):    print("Decorator called")    def inner_function(*args, **kwargs):            print("Calling the function")            func(*args, **kwargs)            print("Function's execution is over")    return inner_function@decorator_exampledef some_function():    print("Executing the function")    # Function logic goes here
0

New to Communities?

Join the community