[Python-ideas] Fwd: Block-Scoped Exception Handlers

Kyle Lahnakoski klahnakoski at mozilla.com
Fri May 6 20:58:19 EDT 2016


On 5/6/2016 7:57 PM, INADA Naoki wrote:
> If many functions have catch clause, it's a very bad code smell.

This is interesting, and the ?fourth? time it was alluded to!  Maybe the
lack of `try` statements is common, and people can still debug problems
despite the loss of causes and stack traces.  

Another discussion made me realize what I am doing differently:  My
problems may be unique because of multi-threaded code and logging.  I
have programmed using multiple threads for a very long time, and have
been catching my exceptions early-and-often so they, and their causes,
are in a single structure.  My exceptions are emitted to the log (with
all causes and traces) all at once or not at all.  This is necessary
when multiple threads are writing to the log; writing out of order, and
interlacing with other threads' log lines.  Now, I mostly write Python,
but I still spawn many threads despite the GIL.  My exception handling
strategy, and my logging strategy, has not changed. 

I see now.  The log generated by a single thread would be much more
readable, with cause preceding effect, and without obfuscating lines
from other threads.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160506/43b1fad4/attachment.html>


More information about the Python-ideas mailing list