私は一般的な例外ハンドラーを作成しようとしています-この回答からインスピレーションを得て、例外の場合に返す引数を設定できる場所。
import contextlib
@contextlib.contextmanager
def handler(default):
try:
yield
except Exception as e:
yield default
def main():
with handler(0):
return 1 / 0
with handler(0):
return 100 / 0
with handler(0):
return 'helllo + 'cheese'
しかし、これは
RuntimeError: generator didn't stop after throw()