python decorator error handling code example

Example 1: 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

Example 2: python decorator for error handling

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