0
How can you catch an exception thrown by another thread in Python?
If I start another thread in "try" block and that thread calls an exception, "except" block doesn't catch it. How can I fix it? Sorry if it's a dumb question 🥴
3 Respostas
0
Do not apologize, and it is not a dumb question, multi-threading is a complicated topic. If you're using Python 3.8 you can try to use:
"threading.excepthook(args, /)"
It is used to "Handle uncaught exception raised by Thread.run()."
https://docs.python.org/3/library/threading.html#threading.excepthook
ps: you can also try this:
https://www.tutorialspoint.com/How-to-catch-a-thread-s-exception-in-the-caller-thread-in-Python
0
You can also use parent exception handling except for exception which is not covered by previous exception handlers..
Try :
....
except (Exception 1) :
....
except (exception n) :
except :
#every other exception can be caught here..
0
Steven M tnx for answer, excepthook doesn't seem to handle an exception by 'except' block in a main thread, does it? I've tried it and it catches the exception but doesn't give the exception to 'except' block anyway, though that's all I need