Skip to main content

Python Exception Based Callbacks

Project description

Python Exception Based Callbacks

https://travis-ci.org/TheSriram/smoothie.svg?branch=master

Add your callbacks to functions as decorators, that are slated to be called as per the Exception raised.

from smoothie.king import Dispenser

def err_callback(*args, **kwargs):
    print("Error handled")

juice = Dispenser()

@juice.attach(exception=IndexError,
              callback=err_callback)
def vending_machine():
    drinks = ['Tea','Coffee', 'Water']
    return drinks[4]

vending_machine()

To run the unit tests,

pip install -r test-requirements.txt
cd smoothie/tests  nosetests -vs``

Project details


Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page