Bug #915: Solved
This bug, the HN thread and how hard it is to fix (<a href="https:&#x2F;&#x2F;bugs.python.org&#x2F;issue39318" rel="nofollow">https:&#x2F;&#x2F;bugs.python.org&#x2F;issue39318</a>) is a pretty good argument against exceptions.<p>A code that looks simple and correct has been hiding a very subtle bug because no one understood the implications of an arbitrary exception being thrown at any point under the caller.<p>And of all the people who looked at the bug not a single one looked at this seemingly simple code and said &quot;oh yeah, that&#x27;s because this code is obviously wrong&quot;. It took someone skilled enough to script gdb to figure out the buggy interactions.<p>So the next time someone makes fun of `if err != nil`, send them the buggy implementation of tempfile.NamedTemporaryFile and ask them to spot the bug.<p>Also, KeyboardInterrupt should not be an exception. It&#x27;s a signal, not an error or exceptional situation that code wants to report to the caller. But once you have a hammer, everything looks like like a nail. In addition to making the code impossible to reason about, no-one can agree what exactly is an exception so they randomly commingle expected errors with exceptional circumstances and, in case of Python, out-of-band signals.<p>(&quot;randomly&quot; as in: why is &quot;open file&quot; throwing an exception when file doesn&#x27;t exist but &quot;find substring&quot; returns -1 when substring doesn&#x27;t exist?)