"""Create error_monitor
Generated by Phi-Octopus Eden
2025-11-06 16:51:27.415377
"""

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


class ErrorMonitor:
    """
    A class for monitoring and handling errors in a function to improve limited error recovery.
    """

    def __init__(self):
        self.error_handlers: Dict[str, Callable[[Exception], None]] = {}

    def register_error_handler(self, exception_type: type[BaseException], handler: Callable[[Exception], None]) -> None:
        """
        Register an error handler for a specific exception type.

        :param exception_type: The type of the exception to handle.
        :param handler: A callable that takes an Exception as its argument and processes it.
        """
        self.error_handlers[str(exception_type)] = handler

    def monitor(self, func: Callable) -> Callable:
        """
        Decorator for monitoring a function's execution.

        :param func: The function to be monitored.
        :return: A wrapped version of the function with error handling.
        """

        def wrapper(*args: Any, **kwargs: Any) -> Any:
            try:
                return func(*args, **kwargs)
            except Exception as e:
                handler_name = str(type(e).__name__)
                if handler_name in self.error_handlers:
                    self.error_handlers[handler_name](e)

        return wrapper


def example_handler(exception: Exception) -> None:
    """
    An example error handler that prints the exception message.

    :param exception: The caught exception.
    """
    print(f"Caught an {type(exception).__name__}: {str(exception)}")


# Example usage
if __name__ == "__main__":
    monitor = ErrorMonitor()
    monitor.register_error_handler(ValueError, example_handler)

    @monitor.monitor
    def test_function(x: int) -> str:
        if x < 0:
            raise ValueError("x must be non-negative")
        return f"x is {x}"

    # Test the function with a valid and invalid input
    print(test_function(5))
    print(test_function(-1))
```

This code defines an `ErrorMonitor` class that can register error handlers for specific exception types. It also includes a decorator to wrap functions, which will use these handlers if an error occurs during execution. The example usage demonstrates how to use the `ErrorMonitor` with a simple function and a custom error handler.