noraise
Project description
noraise
Description
Lightweight utility package, that provides a function decorator to easily catch and print exceptions
Supported Args
name | type | default value | description |
---|---|---|---|
print_exc | bool | True | If True, prints stacktrace |
return_exception | bool | False | If True, returns caught exception |
default_return_value | Optional[any] | None | What to return upon caught exception if 'return_exception' is False |
ignored_error_types | Optional[List[Exception]] | None | In which cases should the stacktrace print be skipped if 'print_exc' is True |
Install
pip install noraise
# or
pip3 install noraise
Usage
from noraise import noraise
@noraise(print_exc=True, return_exception=True, ignored_error_types=[ZeroDivisionError])
def f2():
return 1/0
res = f2()
print(type(res), res)
# This will not catch the crash, and print
#
#
# < ------------------------------------- Caught with @noraise ------------------------------------ >
#
# Traceback (most recent call last):
# File "/Users/kristofk/github/py_noraise/noraise/noraise.py", line 32, in wrapper
# return function(*args, **kwargs)
# File "demo.py", line 5, in f2
# return 1/0
# ZeroDivisionError: division by zero
#
# < ----------------------------------------------------------------------------------------------- >
#
#
# <class 'ZeroDivisionError'> division by zero
Dependencies
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
noraise-0.0.16.tar.gz
(3.7 kB
view hashes)