"""Create fallback_executor
Generated by Phi-Octopus Eden
2025-11-05 22:31:08.065046
"""

```python
from typing import Callable, Any


class FallbackExecutor:
    """
    A class that allows for executing a primary function and provides an option to execute a fallback function in case of failure.

    Attributes:
        primary_func (Callable): The main function to be executed.
        fallback_func (Callable): An optional secondary function to be executed if the primary function fails.
        exceptions_to_catch (tuple[type[BaseException]]): A tuple of exception types that should trigger the fallback.
    """

    def __init__(self, primary_func: Callable, fallback_func: Callable = None, exceptions_to_catch: tuple[type[BaseException]] = (Exception,)):
        self.primary_func = primary_func
        self.fallback_func = fallback_func
        self.exceptions_to_catch = exceptions_to_catch

    def execute_with_fallback(self, *args, **kwargs) -> Any:
        """
        Executes the primary function with provided arguments. If an exception occurs,
        and a fallback function is defined, it attempts to run the fallback function.

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

        Returns:
            The result of the primary function or the fallback function if available.
        """
        try:
            return self.primary_func(*args, **kwargs)
        except self.exceptions_to_catch as e:
            print(f"An error occurred: {e}")
            if self.fallback_func is not None:
                return self.fallback_func(*args, **kwargs)


# Example usage
def divide(a: float, b: float) -> float:
    """
    Divides two numbers.
    Raises ZeroDivisionError when the denominator is zero.

    Args:
        a (float): The numerator.
        b (float): The denominator.

    Returns:
        float: Result of division.
    """
    return a / b


def safe_divide(a: float, b: float) -> float:
    """
    A safe version of divide that returns 0 instead of raising an error when the denominator is zero.

    Args:
        a (float): The numerator.
        b (float): The denominator.

    Returns:
        float: Result of division or 0 if division by zero occurs.
    """
    return a / max(b, 1e-6)


# Create an instance with the divide function and its safe version as fallback
fallback_executor = FallbackExecutor(divide, safe_divide)

# Example calls
result = fallback_executor.execute_with_fallback(10, 2)  # Should be 5.0
print(result)
result = fallback_executor.execute_with_fallback(10, 0)  # Should be a safe value close to infinity
print(result)
```