Added checks for invalid index specifications

I didn't want to change the exception class, as that is of course
a BC break.

Added some extra test cases too.