Skip to content

BranislavBajuzik/ExceptionCatcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ExceptionCatcher

Build Status codecov

General wrapper for catching exceptions

Any exception (Except for KeyboardInterrupt and SystemExit) raised inside ExceptionCatcher context will be caught and suppressed and the whole traceback will be printed out.

Usage

As decorator

@ExceptionCatcher
def foo(a):
    raise BaseException

@ExceptionCatcher(callback=lambda: 42)
def bar(a):
    return 1 / a
    
print(foo())   # None
print(bar(0))  # 42
print(bar(1))  # 1

As context manager

with ExceptionCatcher:
    raise BaseException

with ExceptionCatcher(callback=lambda: 42) as catcher:
    raise BaseException
    
print(catcher.failed)  # True
print(catcher.result)  # 42

About

General wrapper for catching and handling exceptions

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages