"""Create fallback_executor
Generated by Phi-Octopus Eden
2025-11-08 13:03:12.575713
"""

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


class FallbackExecutor:
    """
    A class for handling operations that may fail by providing a fallback function to recover from errors.
    
    Args:
        primary_function: The main function to execute. Raises an exception on failure.
        fallback_function: An optional secondary function that is called if the primary function fails.
        
    Usage example:
    >>> def divide(x, y):
    ...     return x / y
    ...
    >>> def zero_divisor_fallback():
    ...     print("Division by zero occurred! Fallback to default value of 0.")
    ...     return 0
    ...
    >>> executor = FallbackExecutor(primary_function=divide, fallback_function=zero_divisor_fallback)
    >>> result = executor.execute(10, 2)  # No error here.
    5.0
    >>> result = executor.execute(10, 0)  # Error occurs, fallback function is called.
    Division by zero occurred! Fallback to default value of 0.
    0
    """
    
    def __init__(self, primary_function: Callable[..., Any], fallback_function: Optional[Callable[..., Any]] = None):
        self.primary_function = primary_function
        self.fallback_function = fallback_function
    
    def execute(self, *args, **kwargs) -> Any:
        try:
            return self.primary_function(*args, **kwargs)
        except Exception as e:
            if self.fallback_function:
                print(f"Primary function failed: {e}. Calling fallback function.")
                return self.fallback_function(*args, **kwargs)
            else:
                raise


# Example usage
def safe_divide(x, y):
    """Division of x by y with error handling."""
    try:
        return x / y
    except ZeroDivisionError as e:
        print(f"Caught an error: {e}. Fallback to 0.")
        return 0

safe_executor = FallbackExecutor(primary_function=safe_divide, fallback_function=lambda: 0)
result1 = safe_executor.execute(15, 3)   # Should be 5
print(result1)

result2 = safe_executor.execute(15, 0)  # Should fall back to 0 due to division by zero
print(result2)
```