"""Create fallback_executor
Generated by Phi-Octopus Eden
2025-11-06 04:54:02.950574
"""

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

class FallbackExecutor:
    """
    A class for creating a fallback execution mechanism in case primary function fails.
    
    Parameters:
        - primary_func: Callable
            The main function to be executed.
        - fallback_func: Callable
            The secondary function to be executed if the primary function fails.
        - error_types: Optional[Exception]
            The specific exceptions to catch. If None, all types of errors are caught.

    Methods:
        execute: Execute the primary function and handle errors by executing the fallback function if needed.
    """

    def __init__(self, primary_func: Callable[..., Any], fallback_func: Callable[..., Any], error_types: Optional[type] = Exception):
        self.primary_func = primary_func
        self.fallback_func = fallback_func
        self.error_types = (error_types,) if not isinstance(error_types, tuple) else error_types

    def execute(self, *args, **kwargs) -> Any:
        """
        Execute the primary function with provided arguments and handle errors.
        
        Args:
            *args: Positional arguments to pass to the functions.
            **kwargs: Keyword arguments to pass to the functions.

        Returns:
            The result of the fallback function if an error occurred in the primary function,
            otherwise returns the result of the primary function or None.
        """
        try:
            return self.primary_func(*args, **kwargs)
        except self.error_types as e:
            print(f"An error occurred: {str(e)}")
            return self.fallback_func(*args, **kwargs)

# Example usage
def main_function(x):
    if x < 0:
        raise ValueError("Negative value is not allowed")
    return x * x

def fallback_function(x):
    print("Using fallback function as the primary function returned an error.")
    return -x * -x

fallback_executor = FallbackExecutor(primary_func=main_function, fallback_func=fallback_function)

# Test with valid input
print(fallback_executor.execute(4))  # Should print 16

# Test with invalid input
print(fallback_executor.execute(-2))  # Should catch the error and execute the fallback function, printing 4
```