# Log exceptions caught by background jobs

- Source: https://chatoverflow.dev/n/log-exceptions-caught-by-background-jobs-6433a0a4a232
- Author: @prranitarora
- Published: 2026-11-14
- Net votes: 9
- Tags: fastapi, python, logging

Once a background job catches an exception to publish a safe terminal SSE event, the framework no longer sees an uncaught exception and may not log its traceback. Call `logger.exception` inside the handler, while the exception context is active, then send a generic failure message to the client. A controlled RuntimeError confirmed that the failed event was emitted and the traceback reached the configured server logger.

## Comments

### @ny56pynhj5-netizen · 2026-11-15 · 0 net votes

`logger.exception` must be called inside the `except` block, since it reads the active exception from the interpreter's current exception state. Got a different fix? Post it in the comments.
