Skip to main content

A Python library for handling exceptions in a clean and organized way

Project description

HandleException - Python Wrapper Class to Catch Exceptions

PyPI version

HandleException is a Python wrapper class that helps to catch exceptions and raise them to an upper level. With HandleException, you can easily wrap any function that you want to monitor for exceptions and handle them as desired.

Installation

pip install handle-exception

Usage

To use HandleException, simply decorate the function that you want to wrap with the HandleException decorator. For example:

from handle_exception import HandleException

@HandleException
def my_function():
    raise ValueError("Test exception")

In this example, if the function my_function raises an exception, HandleException will catch it and raise it to the upper level. This way, you can handle exceptions in a centralized way, instead of having to write try-except blocks in multiple places.

Custom Exceptions

HandleException also allows you to catch specific custom exceptions by passing a list of exception classes as an argument to the ExceptionRaiser decorator. For example:

from handle_exception import ExceptionRaiser

class CustomException(Exception):
    pass

@ExceptionRaiser(exceptions=[CustomException])
def my_function():
    raise CustomException("This is a custom exception.")

In this example, the function my_function raises a custom exception, CustomException, which will be caught by HandleException.

Example

from handle_exception import HandleException

@HandleException
def divide(a, b):
    return a / b

result = divide(10, 0)
print(result)

In this example, the divide function is decorated with the HandleException decorator. This means that any exceptions raised in the divide function will be caught and handled by the HandleException class. The code is much cleaner and easier to understand, as it doesn't contain a try-except block or have to worry about handling exceptions manually.

Contributing

We welcome contributions to HandleException! If you'd like to contribute, please follow these steps:

  1. Fork the repository.
  2. Create a new branch for your changes.
  3. Make your changes and write tests for them.
  4. Submit a pull request.

License

HandleException is released under the MIT License.

We welcome contributions to this library. If you have an idea for a new feature or have found a bug, please open an issue on Github.

Buy me a Coffee

ko-fi

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

handle_exception-1.0.1.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

handle_exception-1.0.1-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file handle_exception-1.0.1.tar.gz.

File metadata

  • Download URL: handle_exception-1.0.1.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.9.6 requests/2.26.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.1

File hashes

Hashes for handle_exception-1.0.1.tar.gz
Algorithm Hash digest
SHA256 f30f72429d63c14e80950abd202349b1283838e4b352e417c9a95430859f867b
MD5 7cc9f57c27ff391e8cb5d9eb65cf7c69
BLAKE2b-256 dd7c6484f6c5da0c93d97b6e02d99e700abe3f98087bf37603bb92549d6441b2

See more details on using hashes here.

File details

Details for the file handle_exception-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: handle_exception-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.9.6 requests/2.26.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.1

File hashes

Hashes for handle_exception-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6a03f53403a970dcb9a28e8d4fd57869c37c239a13a2c49c4796749417995f43
MD5 e4faad609352d3fef15be99eaeda1cbb
BLAKE2b-256 4cc0f5da34adab6b1005f03c6981a61b80914ced9769dbb1732f41398998e6e0

See more details on using hashes here.

Supported by

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