Re: how to discover what values produced an exception?

Liste des GroupesRevenir à cl python 
Sujet : Re: how to discover what values produced an exception?
De : alan (at) *nospam* csail.mit.edu (Alan Bawden)
Groupes : comp.lang.python
Date : 04. May 2024, 01:29:43
Autres entêtes
Organisation : ITS Preservation Society
Message-ID : <86r0eimq3c.fsf@williamsburg.bawden.org>
References : 1 2 3
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)
Thomas Passin <list1@tompassin.net> writes:

   On 5/3/2024 9:56 AM, Johanne Fairchild via Python-list wrote:
   > How to discover what values produced an exception?  Or perhaps---why
   > doesn't the Python traceback show the values involved in the TypeError?
   > For instance:
   >
   > --8<-------------------------------------------------------->8---
   >>>> (0,0) < 4
   > Traceback (most recent call last):
   >    File "<stdin>", line 1, in <module>
   > TypeError: '<' not supported between instances of 'tuple' and 'int'
   > --8<-------------------------------------------------------->8---
   >
   > It could have said something like:
   >
   > --8<-------------------------------------------------------->8---
   > TypeError: '<' not supported between instances of 'tuple' and 'int'
   >    in (0,0) < 4.
   > --8<-------------------------------------------------------->8---
   >
   > We would know which were the values that caused the problem, which would
   > be very helpful.

   In this example it would not help at all to know the actual values. Knowing
   that you are trying to compare incomparable types is enough.

In general, it absolutely can help.  The programmer can sometimes
recognize where a value of unexpected type came from just by looking at
it, allowing her to quickly deduce just what went wrong without further
investigation.

A good error message shouldn't withhold any information that can
_easily_ be included.  Debugging is more art than science, so there is
no real way to predict what information might prove useful in solving
the crime.  I emphasized "easily" because of course you have to draw the
line somewhere.

The fact that Python error messages often fail to mention the actual
objects that caused the error has always annoyed me.  I've always
presumed that for some reason it just wasn't easy to do.  And it's never
been more than a minor annoyance to me.

So the OP is not wrong for wishing for this.  Other programming
languages do it.  Other Python programmers miss it.

- Alan

Date Sujet#  Auteur
3 May 24 * how to discover what values produced an exception?12Johanne Fairchild
3 May 24 +* Re: how to discover what values produced an exception?4Stefan Ram
4 May 24 i`* Re: how to discover what values produced an exception?3Stefan Ram
4 May 24 i +- Re: how to discover what values produced an exception?1Stefan Ram
4 May 24 i `- Re: how to discover what values produced an exception?1Stefan Ram
3 May 24 +* Re: how to discover what values produced an exception?3Thomas Passin
4 May 24 i`* Re: how to discover what values produced an exception?2Alan Bawden
6 May 24 i `- Re: how to discover what values produced an exception?1Chris Angelico
4 May 24 +- Re: how to discover what values produced an exception?1dieter.maurer
4 May 24 +- Re: how to discover what values produced an exception?12QdxY4RzWzUUiLuE
4 May 24 +- Re: how to discover what values produced an exception?1Stefan Ram
3 May 24 `- Re: how to discover what values produced an exception?1Left Right

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal