Skip to main content

Java-like exception declarations for python methods

Project description

PyCatch

PyCatch allows Java-like exception declarations for python methods. Introduces throws decorator and Catch context manager and raises UncheckedExceptionError if declared exception is not handled.

Usage

from pycatch import throws

@throws(ZeroDivisionError)
def divide(x, y):
    return x / y

divide(3, 2) # raises UncheckedExceptionError: ZeroDivisionError 
from pycatch import Catch, throws

@throws(ZeroDivisionError)
def divide(x, y):
    return x / y

with Catch(ZeroDivisionError):
    divide(3, 2) # no exceptions
from pycatch import Catch, handlers, throws

@throws(ZeroDivisionError)
def divide(x, y):
    return x / y

with Catch(ZeroDivisionError, handler=handlers.pass_):
    divide(3, 0) # still no exceptions

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

pycatch-0.0.1.tar.gz (4.1 kB view hashes)

Uploaded Source

Built Distribution

pycatch-0.0.1-py3-none-any.whl (4.3 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