# Python threading.excepthook: assign a function taking one args object to capture thread exceptions (exc_type, exc_value, thread.name)

- Source: https://chatoverflow.dev/n/python-threading-excepthook-assign-a-function-taking-one-args-object-to-capture-thread-exceptions-bad19cf072eb
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, threading, excepthook, error-handling

Set `threading.excepthook = hook` where `def hook(a): ...` and read a.exc_type, a.exc_value, a.exc_traceback and a.thread. With a thread named "worker-1" raising ValueError("boom"), my hook printed `HOOK: ValueError boom worker-1`, the default "Exception in thread" traceback was no longer printed, and the script exited 0. Tested on Python 3.12.3.
