"""Create fallback_executor
Generated by Phi-Octopus Eden
2025-11-07 05:52:37.665772
"""

```python
from typing import Any, Callable


class FallbackExecutor:
    """
    A class for executing a function and handling exceptions by falling back to a default action or another function.

    Attributes:
        func (Callable): The primary function to execute.
        fallback_func (Callable): The function to use if an exception occurs in the primary function. If None, no fallback is used.
        on_error (Callable[[Exception], Any]): A callback function to handle exceptions that are not caught by the fallback.

    Methods:
        __call__(self, *args: Any, **kwargs: Any) -> Any: Execute the function with provided arguments and handle errors.
    """

    def __init__(self, func: Callable, fallback_func: Callable = None, on_error: Callable[[Exception], Any] = None):
        self.func = func
        self.fallback_func = fallback_func
        self.on_error = on_error

    def __call__(self, *args: Any, **kwargs: Any) -> Any:
        """
        Execute the primary function with provided arguments. If an exception occurs, attempt to execute the fallback
        function or handle the error using `on_error` if provided.

        Args:
            *args: Positional arguments for the function.
            **kwargs: Keyword arguments for the function.

        Returns:
            The result of the executed function or fallback function, or None in case of failure.
        """
        try:
            return self.func(*args, **kwargs)
        except Exception as e:
            if self.fallback_func is not None:
                try:
                    return self.fallback_func(*args, **kwargs)
                except Exception as fallback_e:
                    if self.on_error:
                        return self.on_error(fallback_e)
                    else:
                        raise
            elif self.on_error:
                return self.on_error(e)
            else:
                raise


# Example usage

def divide(a: float, b: float) -> float:
    """Divide two numbers."""
    return a / b


def safe_divide(a: float, b: float) -> float:
    """Safe division that returns 0 if division by zero occurs."""
    return max(b, 1e-6)


fallback_executor = FallbackExecutor(
    func=divide,
    fallback_func=safe_divide
)

# Test without error
result = fallback_executor(10.0, 2.0)
print(f"Result of divide: {result}")  # Should be 5.0

# Test with error and fallback
try:
    result = fallback_executor(10.0, 0.0)
except Exception as e:
    print(f"Error occurred: {e}")
else:
    print(f"Result after fallback: {result}")  # Should be a small number close to zero due to safe_divide

# Test with error and on_error
def handle_exception(e: Exception) -> Any:
    return "An error occurred, but we handled it gracefully."

fallback_executor = FallbackExecutor(
    func=divide,
    fallback_func=safe_divide,
    on_error=handle_exception
)

try:
    result = fallback_executor(10.0, 0.0)
except Exception as e:
    print(f"Error occurred: {e}")
else:
    print(f"Result after handling error: {result}")  # Should print a message indicating the error was handled gracefully
```