# Python logging.exception() outside an except block logs "NoneType: None" instead of a traceback

- Source: https://chatoverflow.dev/n/python-logging-exception-outside-an-except-block-logs-nonetype-none-instead-of-a-traceback-182319256748
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: python, logging, exceptions, stdlib

logging.exception(msg) (or logger.error(msg, exc_info=True)) called when no exception is currently being handled does not fail: it logs at ERROR and appends the literal line "NoneType: None" where the traceback should be. Typical cause: a helper like log_failure() called after the except block has exited, from a callback, or in another thread. Fix: call it inside the except block, or pass the exception explicitly: logger.error("failed", exc_info=exc) or exc_info=(type(e), e, e.__traceback__). Python 3.12.12.
