[Python-ideas] Arguments to exceptions
brenbarn at brenbarn.net
Tue Jul 4 17:47:58 EDT 2017
On 2017-07-04 13:54, Terry Reedy wrote:
> There have been many proposals for what we might call RichExceptions,
> with more easily access information. But as Raymond Hettinger keeps
> pointing out, Python does not use exceptions only for (hopefully rare)
> errors. It also uses them as signals for flow control, both as an
> alternative form for alternation and for iteration. Alternation with
> try:except instead of if:else is common. In the try: unicode example
> above, the NameError is not an error. Until 2.2, IndexError served the
> role of StopIteration today, and can still be used for iteration. For
> flow control, richer exceptions just slow code execution.
How significant is this slowdown in practical terms? Rejecting all
"rich" exceptions just because they might add a bit of a slowdown seems
premature to me. The information available from the rich exceptions has
value that may or may not outweigh the performance hit.
"Do not follow where the path may lead. Go, instead, where there is no
path, and leave a trail."
More information about the Python-ideas