Skip to main content

Simple Exception Handler Decorator

Project description

Exception Handler decorator allows developers to specify specific exception types to handle and provide a handler function for each of those exception types. The decorator also provides an option to specify a default return value to be used when an unhandled exception occurs. Additionally, the decorator tracks the number of times each exception type has been seen and raises a MaxRepeatedExceptionsError when a specific exception type exceeds a specified maximum number of occurrences.

The decorator uses the exception_handler function as a wrapper for the decorated function. The function accepts four parameters:

  • handlers (Dict[Type[Exception], HandlerFuncType]): A dictionary where the keys are exception types and the values are the corresponding
  • handler functions for those exception types.
  • default_return (Optional[Any]): A default return value to be used when an unhandled exception occurs.
  • max_repeated_exceptions (int): The maximum number of times an exception type can be seen before a MaxRepeatedExceptionsError is raised.
  • seen_exceptions (Optional[DefaultDict[Type[Exception], List[int]]]): A defaultdict used to keep track of the number of times each exception type has been seen.

The read_env module is used to read the maximum number of repeated exceptions that can occur from an environment variable.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

exception_handler_plus-0.1.0.tar.gz (4.3 kB view hashes)

Uploaded Source

Built Distribution

exception_handler_plus-0.1.0-py3-none-any.whl (4.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page