A simple library for decorating functions that can raise exceptions.
pip install can-raise
from can_raise import can_raise
@can_raise(ValueError)
def validate_int(x: int):
if x < 0:
raise ValueError
return x
If you don't provide any value, it will default to Exception
@can_raise()
def raise_exc():
raise TypeError # or any other exception
You can also provide more than one argument
@can_raise(ValueError, TypeError)
def raise_exc(x: int):
if x < 0:
raise ValueError
if x > 0:
raise TypeError
return x