denizdogan / hungry

Python library for easily "eating" exceptions in functions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

hungry

image

Python library for easily "eating" exceptions in functions. Eating can mean either returning a default value or calling another function.

Introduction

This library is basically just a function, namely hungry.eat. Initially, I wrote it for a document parser in which there was a lot of exception handling logic for stuff I didn't really care particularly much about.

Example usage

Eat all exceptions and return None if one was raised:

Eat ValueError exceptions and return 0 if one was raised:

Eat IndexError and ValueError and fall back to function bar if one of them is raised:

In the example above, bar will be passed the exception as the first argument, followed by all the other arguments and keyword arguments in the decorated function. This means that bar would have e.g. the following signature:

Notes

This library will not catch exceptions and continue executing the following code. Whenever it eats an exception, it immediately returns error_value or calls error_handler.

TODO

Complete the test suite.

About

Python library for easily "eating" exceptions in functions

License:MIT License


Languages

Language:Python 100.0%