On Sun, Sep 12, 2021 at 10:49 PM Ram Krishna <srinivasr2...@gmail.com> wrote:
>
> I guess having subclass for implementation errors to distinguish will be very 
> helpful, Typeerror has become very generic and finding solution is like 
> searching a needle in haystack for the new developers.
>
> Eg- TypeError: ‘int’ object is not iterable
>
> students=int(input('Please enter the number of students in the class: '))
>
> for number in students:
>         math_grade=(input("Enter student's Maths grade: "))
>         science_grade=(input("Enter student's Science grade: "))
>         social_grade=(input("Enter student's Scoial grade: "))
>
> Common homeworks/tutorial for beginners who find difficult to understand why 
> this error occurred. So a fine grained exception would be lot easier to 
> understand and resolve quickly.

Learning how to debug is part of learning to write software. (Maybe
the biggest part.) Changing the type of that TypeError won't help; the
key is figuring out why you're trying to iterate over an integer. The
exception text is, to new developers, far more important than the
actual type; I'd say that the type only really becomes significant
when you're trying to catch the exception - that is to say, when
exceptions DON'T mean errors.

Also, novice programmers often forget (or fail to notice) that Python
exceptions point you to the exact place where the error happened
(especially in 3.10+); IME pointing someone to the right line of code
is far more valuable than identifying the cause of the error, unless
all of your students are creating the exact same bugs. (And sometimes
even then. Maybe you have an exercise that is specifically designed to
guide someone towards a wrong piece of code, experience a particular
bug, and learn from it.) Most novices that I've taught have gone
straight for the exception message, ignored the type name at the
start, and ignored the line of code. And if I'm completely honest,
I've made that same mistake myself, too - ended up looking in
completely the wrong place...

(The one thing that often trips people up is that, if an exception
points to line X, the bug might be on line X-1, especially if it's a
missed close parenthesis or something. I don't think there's an easy
technical solution to that, but it's something I do have to point out
to people fairly often.)

ChrisA
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/EL7TAOXEGQ2AILGKW5SXY3UR3J4O6EVD/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to