[Python-ideas] Arguments to exceptions

Steven D'Aprano steve at pearwood.info
Wed Jul 5 07:36:35 EDT 2017

On Tue, Jul 04, 2017 at 11:37:51PM -0400, Terry Reedy wrote:

> I personally been on the side of wanting richer exceptions.

Could you explain what you would use them for? Ken has give two 
use-cases which I personally consider are relatively niche, and perhaps 
even counter-productive:

- translation into the user's native language;

- providing some sort of "did you mean...?" functionality.

Jeff Walker also suggested being able to extract the line and column 
from certain kinds of JSON errors. (But that would depend on the json 
module having an API that supports that use-case. You can't just say 
line_no = exception.args[0] if there's no guarantee that it actually 
will be the line number.)

What would you use these for? I imagine you're thinking of this as the 
maintainer of IDLE?

> So what has 
> been the resistance?  Speed is definitely one.  Maybe space?  Probably 
> maintenance cost.  Lack of interest among true 'core' (C competent) 
> developers?

Where there is a clear and obvious need the core devs have spent the 
time to give the exception class a rich API for extracting useful 
information. See OSError, which offers named attributes for the errno, 
error message, Windows error number (when appropriate) and two file 

I expect that the fact that few of the other builtin or stdlib 
exceptions similarly offer named attributes is because nobody thought
of it, or saw any need.


More information about the Python-ideas mailing list