"""Create fallback_executor
Generated by Phi-Octopus Eden
2025-11-08 02:31:53.487769
"""

```python
from typing import Callable


class FallbackExecutor:
    """
    A class for executing a main function with fallbacks in case of errors.
    
    Parameters:
        - main_func: The primary function to execute. It should accept positional and keyword arguments.
        - fallback_funcs: List of functions that will be tried as fallbacks if the main function raises an error.
                          Each function should have the same signature as `main_func`.
        - max_attempts: Maximum number of attempts including the initial attempt with the main function.

    Usage:
        >>> def add(a, b):
        ...     return a + b
        ...
        >>> def subtract(a, b):
        ...     return a - b
        ...
        >>> def multiply(a, b):
        ...     return a * b
        ...
        >>> fallback_executor = FallbackExecutor(
        ...     main_func=add,
        ...     fallback_funcs=[subtract, multiply],
        ...     max_attempts=3
        ... )
        >>> result = fallback_executor.execute(5, 3)
    """

    def __init__(self, main_func: Callable, fallback_funcs: list[Callable], max_attempts: int):
        self.main_func = main_func
        self.fallback_funcs = fallback_funcs
        self.max_attempts = max_attempts

    def execute(self, *args, **kwargs) -> any:
        """
        Execute the main function or its fallbacks with error recovery.
        """
        attempts = 1
        while attempts <= self.max_attempts:
            try:
                return self.main_func(*args, **kwargs)
            except Exception as e:
                if self.fallback_funcs and (attempts < self.max_attempts):
                    next_fallback = self.fallback_funcs.pop(0)
                    print(f"Error occurred: {e}, trying fallback function...")
                    attempts += 1
                else:
                    raise Exception("All attempts failed") from e

        # If no fallback works, re-raise the last error.
        raise


# Example usage
def add(a, b):
    return a + b

def subtract(a, b):
    return a - b

def multiply(a, b):
    return a * b

fallback_executor = FallbackExecutor(
    main_func=add,
    fallback_funcs=[subtract, multiply],
    max_attempts=3
)

result = fallback_executor.execute(5, 3)
print(f"Result: {result}")
```