"""Create fallback_executor
Generated by Phi-Octopus Eden
2025-11-08 17:52:22.296307
"""

```python
from typing import Any, Callable, Optional


class FallbackExecutor:
    """
    A class that provides a mechanism for executing tasks with fallbacks in case of errors.

    Attributes:
        primary_exec: The primary function to execute.
        fallback_func: The fallback function to use if the primary fails.
    """

    def __init__(self, primary_exec: Callable[..., Any], fallback_func: Optional[Callable[..., Any]] = None):
        """
        Initialize the FallbackExecutor with a primary and optional fallback function.

        Args:
            primary_exec: A callable that represents the main task to execute.
            fallback_func: An optional callable that represents the fallback action if needed.
        """
        self.primary_exec = primary_exec
        self.fallback_func = fallback_func

    def __call__(self, *args: Any, **kwargs: Any) -> Any:
        """
        Execute the primary function. If it fails, attempt to execute the fallback.

        Args:
            *args: Positional arguments passed to the primary function.
            **kwargs: Keyword arguments passed to the primary function.

        Returns:
            The result of the execution or the fallback if an error occurs.
        """
        try:
            return self.primary_exec(*args, **kwargs)
        except Exception as e:
            print(f"Primary exec failed with exception: {e}")
            if self.fallback_func is not None:
                try:
                    return self.fallback_func(*args, **kwargs)
                except Exception as fallback_exception:
                    print(f"Fallback function also failed with exception: {fallback_exception}")
                    raise


# Example usage
def primary_task(x):
    """A sample task that can potentially fail."""
    if x == 0:
        raise ValueError("Divide by zero error")
    return 1 / x

def fallback_task(x):
    """Fallback logic for when the primary task fails."""
    print(f"Executing fallback with input: {x}")
    return -1 * (1 / x)

# Create an instance of FallbackExecutor
executor = FallbackExecutor(primary_task, fallback_func=fallback_task)

# Test execution
print("Testing primary task with valid input:")
result = executor(5)
print(result)  # Expected output: 0.2

print("\nTesting primary task with invalid input to trigger exception and fallback:")
try:
    result = executor(0)
except Exception as e:
    print(e)  # Expected error handling
```