"""Create fallback_executor
Generated by Phi-Octopus Eden
2025-11-06 09:24:22.143459
"""

```python
from typing import Callable, Any, Optional


class FallbackExecutor:
    """
    A class for executing a function with fallback behavior in case of errors.

    Attributes:
        primary_function (Callable): The main function to execute.
        secondary_function (Callable): The fallback function to use if the primary fails.
        error_types (tuple[type[BaseException]]): Types of exceptions that should trigger the fallback.

    Methods:
        execute: Execute the primary function, and switch to the secondary on errors.
    """

    def __init__(self,
                 primary_function: Callable[..., Any],
                 secondary_function: Optional[Callable[..., Any]] = None,
                 error_types: tuple[type[BaseException], ...] = (Exception,)
                 ):
        """
        Initialize FallbackExecutor with a primary function and optional fallback.

        Args:
            primary_function: The main function to attempt executing.
            secondary_function: The function to use in case of an exception from the primary. Defaults to None.
            error_types: Types of exceptions that should trigger the fallback. Defaults to (Exception,).
        """
        self.primary_function = primary_function
        self.secondary_function = secondary_function
        self.error_types = error_types

    def execute(self, *args, **kwargs) -> Any:
        """
        Execute the primary function with provided arguments and keyword arguments.
        If an exception of type in `error_types` occurs, attempt to run the secondary function.

        Args:
            *args: Positional arguments for the functions.
            **kwargs: Keyword arguments for the functions.

        Returns:
            The result of the successful execution or None if both fail.

        Raises:
            Exception: If no fallback is provided and an error occurs in primary_function.
        """
        try:
            return self.primary_function(*args, **kwargs)
        except self.error_types as e:
            if self.secondary_function:
                print(f"Primary function failed with {type(e).__name__}, attempting fallback.")
                return self.secondary_function(*args, **kwargs)
            else:
                raise Exception("No fallback provided and primary function execution failed.") from e


# Example Usage
def divide_numbers(x: int, y: int) -> float:
    """
    Divide two numbers.

    Args:
        x: Numerator.
        y: Denominator.

    Returns:
        The result of division.
    """
    return x / y

def safe_divide(x: int, y: int) -> Optional[float]:
    """
    Safe divide function that handles division by zero gracefully.

    Args:
        x: Numerator.
        y: Denominator.

    Returns:
        The result of division or None if division by zero occurs.
    """
    return x / y if y else None

fallback_executor = FallbackExecutor(divide_numbers, secondary_function=safe_divide)

# Test the execution
result = fallback_executor.execute(10, 2)  # Expected: 5.0
print(f"Result of successful division: {result}")

result = fallback_executor.execute(10, 0)  # Expected: None (due to safe divide handling)
print(f"Result when dividing by zero: {result}")
```