Skip to content

Java-like exception declarations for python methods.

License

Notifications You must be signed in to change notification settings

misatlawa/pycatch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Java-like exception declarations for python methods.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages