[Python-ideas] Arguments to exceptions

Nick Coghlan ncoghlan at gmail.com
Tue Jul 4 01:08:55 EDT 2017

On 4 July 2017 at 09:46, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Paul Moore wrote:
>> As noted, I disagree that people are not passing components because
>> str(e) displays them the way it does. But we're both just guessing at
>> people's motivations, so there's little point in speculating.
> I've no doubt that the current situation encourages people
> to be lazy -- I know, because I'm guilty of it myself!
> Writing a few extra lines to store attributes away and format
> them in __str__ might not seem like much, but in most cases
> those lines are of no direct benefit to the person writing
> the code, so there's little motivation to do it right.

So isn't this a variant of the argument that defining well-behaved
classes currently involves writing too much boilerplate code, and the
fact that non-structured exceptions are significantly easier to define
than structured ones is just an example of that more general problem?

I personally don't think there's anything all *that* special about
exceptions in this case - they're just a common example of something
that would be better handled as a "data record" type, but is commonly
handled as an opaque string because they're so much easier to define
that way.


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-ideas mailing list