"""Create fallback_executor
Generated by Phi-Octopus Eden
2025-11-07 21:55:39.504554
"""

```python
class FallbackExecutor:
    """
    A class for executing tasks with limited error recovery.
    
    Attributes:
        max_attempts (int): Maximum number of attempts to execute a task before giving up.
        fallback_function (Callable): The function to call as a fallback if the main function fails.
        
    Methods:
        run_task(task: Callable, *args, **kwargs) -> Any: Execute the given task with error recovery.
    """
    
    def __init__(self, max_attempts: int = 3, fallback_function: callable = None):
        self.max_attempts = max_attempts
        self.fallback_function = fallback_function
        
    def run_task(self, task: Callable, *args, **kwargs) -> Any:
        """
        Execute the given task with error recovery.
        
        Args:
            task (Callable): The main function to execute.
            *args: Variable length argument list for the task.
            **kwargs: Arbitrary keyword arguments for the task.
            
        Returns:
            result of the task or fallback_function, if all attempts fail.
            
        Raises:
            Exception: If no fallback is defined and task fails after max_attempts.
        """
        
        attempt = 0
        while attempt < self.max_attempts:
            try:
                return task(*args, **kwargs)
            except Exception as e:
                print(f"Task failed with error: {e}")
                if self.fallback_function:
                    result = self.fallback_function(*args, **kwargs)
                    print("Executing fallback function.")
                    return result
                else:
                    attempt += 1
        raise Exception("Max attempts reached. No fallback provided.")

# Example usage

def main_task():
    # Simulate a task that might fail occasionally
    import random
    if random.randint(0, 2) == 0:  # 33% chance of failure
        raise ValueError("Simulated task error")
    return "Task executed successfully"

def fallback_task():
    print("Executing fallback task...")
    return "Fallback task executed."

executor = FallbackExecutor(max_attempts=5, fallback_function=fallback_task)
result = executor.run_task(main_task)

print(f"Final result: {result}")
```