"""Create fallback_executor
Generated by Phi-Octopus Eden
2025-11-07 22:58:23.684285
"""

```python
from typing import Callable, Any


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

    Parameters:
        - main_func: The primary function to execute.
        - fallback_funcs: A list of functions that will be attempted if the main function fails.
        - exception_types: A tuple of exceptions that should trigger fallback execution. If None, it catches all exceptions.

    Usage:
    >>> def divide(x, y):
    ...     return x / y
    ...
    >>> def safe_divide(x, y):
    ...     try:
    ...         return divide(x, y)
    ...     except ZeroDivisionError as e:
    ...         print(f"Caught an error: {e}")
    ...         return 0
    ...
    >>> fallback_funcs = [safe_divide]
    >>> executor = FallbackExecutor(main_func=divide, fallback_funcs=fallback_funcs, exception_types=(ZeroDivisionError,))
    >>> result = executor.execute(10, 2)
    >>> print(result)  # Output: 5.0
    """

    def __init__(self, main_func: Callable[..., Any], fallback_funcs: list[Callable[..., Any]], exception_types: tuple[type[BaseException], ...] = None):
        self.main_func = main_func
        self.fallback_funcs = fallback_funcs
        self.exception_types = exception_types

    def execute(self, *args: Any, **kwargs: Any) -> Any:
        try:
            return self.main_func(*args, **kwargs)
        except (Exception,) as e:
            if not self.exception_types or isinstance(e, self.exception_types):
                for fallback in self.fallback_funcs:
                    result = fallback(*args, **kwargs)
                    if result is not None:
                        return result
        raise


# Example usage
def divide(x: int, y: int) -> float:
    return x / y

def safe_divide(x: int, y: int) -> float | int:
    try:
        return divide(x, y)
    except ZeroDivisionError as e:
        print(f"Caught an error: {e}")
        return 0

fallback_funcs = [safe_divide]
executor = FallbackExecutor(main_func=divide, fallback_funcs=fallback_funcs, exception_types=(ZeroDivisionError,))
result = executor.execute(10, 2)
print(result)  # Output: 5.0
```