Title: IndexError should (must?) report the index in error!
Type: enhancement Stage: resolved
Components: Versions: Python 3.4
Status: closed Resolution: duplicate
Dependencies: Superseder: Add index attribute to IndexError
View: 18162
Assigned To: Nosy List: kedar mhaswade, r.david.murray
Priority: normal Keywords:

Created on 2015-08-08 14:55 by kedar mhaswade, last changed 2015-08-08 15:21 by r.david.murray. This issue is now closed.

Messages (2)
msg248272 - (view) Author: kedar mhaswade (kedar mhaswade) Date: 2015-08-08 14:55
I am a n00b Python programmer. So far, I am loving Python! Thank you.

Apologies if this has been already reported. A rudimentary search did not fetch anything and hence I am filing this as an enhancement request. If it has been already reported, please point me in the right direction so that I can stand corrected.

I believe following experience could be improved:
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 23 2015, 02:52:03) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> l = []
>>> l[2]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: list index out of range

if the message would indicate the index in error. This, I believe, is a low-hanging fruit that has several debugging benefits.

I hate to compare things, but I do want to note that Java does better in this regard:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 10
	at Foo.main(
msg248273 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-08-08 15:21
Although this isn't a strict duplicate of issue 18162, the strict duplicate, issue 1534607, was closed as a duplicate of issue 18162, so I'm doing the same here.  Issue 18162 will address this issue by providing a useful default message that the interpreter would then use.
Date User Action Args
2015-08-08 15:21:20r.david.murraysetstatus: open -> closed

superseder: Add index attribute to IndexError

nosy: + r.david.murray
messages: + msg248273
resolution: duplicate
stage: resolved
2015-08-08 14:55:20kedar mhaswadecreate