"""Create fallback_executor
Generated by Phi-Octopus Eden
2025-11-07 10:25:00.002921
"""

```python
class FallbackExecutor:
    """
    A class designed to handle exceptions in function execution and provide fallback behaviors.

    Args:
        main_function (Callable): The primary function that needs to be executed.
        fallback_function (Callable, optional): The secondary function that will run if the main function fails. Defaults to None.

    Methods:
        execute: Attempts to call the main function with given arguments. If it raises an exception, attempts to use the fallback function.
    """

    def __init__(self, main_function: callable, fallback_function: callable = None):
        self.main_function = main_function
        self.fallback_function = fallback_function

    def execute(self, *args, **kwargs) -> any:
        """
        Executes the main function with given arguments. If an exception is raised,
        tries to call the fallback function if provided.

        Args:
            *args: Positional arguments for the main function.
            **kwargs: Keyword arguments for the main function.

        Returns:
            The result of the main_function or fallback_function, depending on success.
        """
        try:
            return self.main_function(*args, **kwargs)
        except Exception as e:
            if self.fallback_function is not None:
                print(f"Error occurred in main function: {e}")
                return self.fallback_function(*args, **kwargs)
            else:
                raise


# Example usage
def divide(a: int, b: int) -> float:
    """
    Divides two numbers and returns the result.
    """
    return a / b

def safe_divide(a: int, b: int) -> float:
    """
    A safer version of the division function that avoids division by zero.
    """
    if b == 0:
        print("Division by zero detected. Returning zero instead.")
        return 0
    else:
        return a / b


fallback_executor = FallbackExecutor(main_function=divide, fallback_function=safe_divide)

# Test cases

try:
    result = fallback_executor.execute(10, 2)
except Exception as e:
    print(f"An exception occurred: {e}")

print("Result of safe division:", result)  # Should print "5.0"

try:
    result = fallback_executor.execute(10, 0)
except Exception as e:
    print(f"An exception occurred: {e}")

print("Result when dividing by zero:", result)  # Should print "0"
```