1

Python 3で呼び出し元に発生する特定の例外を無視するにはどうすればよいですか?

例:

def do_something():
    try:
        statement1
        statement2
    except Exception as e:
        # ignore the exception
        logging.warning("this is normal, exception is ignored")


try:
    do_something()
except Exception as e:
    # this is unexpected control flow, the first exception is already ignored !! 
    logging.error("unexpected error")
    logging.error(e)  # prints None

最後にスローされた例外が Python で記憶されているため、例外をスローするステートメントに関与するオブジェクトの一部が無期限に保持されている」と述べた人がいるのを見つけ、この場合は「sys.exc_clear()」を使用するように言及されました。 Python 3ではもう利用できません.python3で例外を完全に無視するにはどうすればよいですか?

4

1 に答える 1