News for hackers. Stuff that matters.
Re:Python Practices for Efficient Code: Performance, Memory,... by TFortunato on Friday August 18, 2017 @03:42PM (#15049136)
Out of curiosity, is there any overhead to the python exception mechanism if you don't hit an exception (ie just by wrapping things in a try block)

I come from an embedded background, where in some c++ projects, we would disable exceptions for various reasons, including the memory overhead, which is why I ask..

Re:Python Practices for Efficient Code: Performance, Memory,... by dom0 on Friday August 18, 2017 @05:24PM (#15049834)
Exception handlers in CPython work by having an instruction store the offset to the start of the handler code which is stored on a stack attached to the frame (iirc). So the cost of a "try:" block is pretty low (for Python, anyway).

The handlers themselves are pretty basic, an "except SomeError" pretty much translates to "if isinstance(exc, SomeError):".