"""Create fallback_executor
Generated by Phi-Octopus Eden
2025-11-08 11:28:34.538796
"""

```python
from typing import Callable, Any


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

    Args:
        main_function: The primary function to execute.
        fallback_functions: A list of functions that will be attempted if the
                            main function fails. The first one that succeeds
                            (returns without raising an exception) will be used.
        error_handler: An optional function that will receive any caught
                       exceptions and can modify behavior accordingly.

    Raises:
        If none of the fallbacks succeed, the last raised exception is re-raised.
    """

    def __init__(self,
                 main_function: Callable[[], Any],
                 fallback_functions: list[Callable[[], Any]],
                 error_handler: Callable[[Exception], None] = None):
        self.main_function = main_function
        self.fallback_functions = fallback_functions
        self.error_handler = error_handler

    def execute(self) -> Any:
        try:
            return self.main_function()
        except Exception as e:
            if self.error_handler:
                self.error_handler(e)

            for func in self.fallback_functions:
                try:
                    return func()
                except Exception as fallback_exception:
                    if self.error_handler:
                        self.error_handler(fallback_exception)
                    continue

            raise  # If no fallback succeeded, re-raise the last exception


# Example usage
def main_operation() -> str:
    """Simulate a risky operation that may fail."""
    import random
    if random.randint(0, 1) == 0:
        print("Main function failed")
        raise ValueError("Something went wrong!")
    return "Main function succeeded"


def fallback1() -> str:
    """First fallback to try"""
    print("Fallback 1 is executing")
    return "Fallback 1 executed successfully"


def fallback2() -> str:
    """Second fallback to try"""
    print("Fallback 2 is executing")
    raise ValueError("Fallback 2 failed with an error")


# Create FallbackExecutor instance
executor = FallbackExecutor(main_operation, [fallback1, fallback2])

try:
    result = executor.execute()
except Exception as e:
    print(f"Failed to execute main or fallback functions: {e}")

print(result)  # Expected output is the message from fallback1 if it succeeds.
```

This Python code defines a `FallbackExecutor` class that encapsulates error handling and provides a way to define primary operations along with multiple fallbacks. The example usage demonstrates how to use this class in a practical scenario where the main function might fail, but subsequent fallback functions can be tried until one succeeds or all fail, in which case the last failure is re-raised as an exception.