"""Create error_monitor
Generated by Phi-Octopus Eden
2025-11-08 09:33:07.703926
"""

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


class ErrorMonitor:
    """
    A class for monitoring and handling errors in a function or block of code.
    
    Attributes:
        func: The function to be monitored.
        recovery_func: An optional function to handle the error when it occurs.
        log_errors: Whether to log errors. Default is True.
    """

    def __init__(self, func: Callable[..., Any], recovery_func: Optional[Callable[[BaseException], None]] = None, log_errors: bool = True):
        self.func = func
        self.recovery_func = recovery_func
        self.log_errors = log_errors

    def __call__(self, *args, **kwargs) -> Any:
        """
        Executes the monitored function and handles any errors that occur.

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

        Returns:
            The result of the function if no error occurs or after recovery.
        """
        try:
            return self.func(*args, **kwargs)
        except Exception as e:
            if self.recovery_func:
                self.recovery_func(e)
            elif self.log_errors:
                print(f"An error occurred: {e}")
            # Optionally re-raise the exception to propagate it further
            raise


# Example usage:

def risky_function(x):
    """
    A function that may fail based on input.
    
    Args:
        x: An integer value.

    Raises:
        ValueError: If `x` is not a positive number.
    """
    if x <= 0:
        raise ValueError("Input must be a positive number")
    return x ** 2


def custom_recovery(error):
    """
    A simple recovery function that prints the error and sets it to zero.

    Args:
        error: The caught exception object.
    """
    print(f"Recovering from {error}")
    # Here you can perform specific cleanup or recovery actions
    pass


# Using ErrorMonitor with a custom recovery function
safe_risky_function = ErrorMonitor(risky_function, recovery_func=custom_recovery)

try:
    result = safe_risky_function(-5)
except ValueError as e:
    print(f"Failed to get the result: {e}")

print("Program continues execution after error handling.")
```

This code snippet creates a `ErrorMonitor` class that wraps around any function and provides error monitoring and recovery. It includes an example usage where a risky function is monitored for errors, and a custom recovery function handles them if necessary.