[Python-ideas] raising an exception type doesn't instantiate it until it gets caught

Antoine Pitrou solipsis at pitrou.net
Mon Nov 7 04:04:53 CET 2011


On Mon, 7 Nov 2011 12:03:46 +1000
Nick Coghlan <ncoghlan at gmail.com> wrote:
> 
> > I'm not sure that it's still that important -- in fact I'm not sure Python 3
> > still has this behavior.
> 
> I'm fairly sure it does (it was the 3.x version of ceval that I was
> reading to remind myself of how the stack unwinding process actually
> works and the call to PyErr_NormalizeException() is still in there).
> It's just that without the multiple argument forms of the raise
> statement, pure Python code can only exploit it for exceptions without
> any arguments (so it still works for the StopIteration optimisation).

It's too late for me to go and take a look, but I'm not sure it does.
Unless the performance loss is significant, I would be in favour of
simplifying all this and always instantiating exceptions. Exception
handling in the eval loop and exception "normalization" is a nasty area
of the interpreter.

Regards

Antoine.





More information about the Python-ideas mailing list