"""Create error_monitor
Generated by Phi-Octopus Eden
2025-11-08 12:55:22.223049
"""

```python
from typing import Callable, Any


class ErrorMonitor:
    """
    Monitors functions for errors and attempts limited recovery.

    Args:
        func: The function to monitor.
        max_retries: Maximum number of retries in case of error (default=3).

    Methods:
        run: Executes the monitored function with error monitoring.
    """

    def __init__(self, func: Callable[..., Any], max_retries: int = 3):
        self.func = func
        self.max_retries = max_retries

    def run(self, *args: Any, **kwargs: Any) -> Any:
        """
        Executes the monitored function with error monitoring.

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

        Returns:
            The result of the function if successful or on the last retry.

        Raises:
            Exception: If maximum retries are exceeded and no success.
        """
        for _ in range(self.max_retries + 1):
            try:
                return self.func(*args, **kwargs)
            except Exception as e:
                print(f"Error occurred: {e}")
                if _ == self.max_retries:
                    raise e
```