> In Go the text returned with errors and panics are sometimes used when
> checking to see what error you had. Code might exist that says:
>
> defer func() {
> if p = recover(); p != nil {
> if re, ok := p.(error); ok && strings.Contains(re.Error, "slice
> bounds out of range") {
> // Oh, I can handle this!
> }
> }
> }
>
> Changing a well known error/panic string is sort of like creating a new
> errno. I am not saying anyone is looking at this string, but someone
> certainly might be. These messages should not be changed lightly.
I agree that it is not something to change lightly, but I also want to
point out that we have never made a promise that these will not
change. If you can convince us that there is a compelling reason to
detect a specific kind of runtime error, we'll make a specific type
for it in package runtime. Of course, that's not something that will
be changed lightly either, and I'm skeptical you'll convince us in
this case.
To answer the original request for more information here: I agree that
it would be great to have more information, but at the same time we
are trying to minimize both the performance impact and the size of the
generated code for the bounds checks. The main reason there's no
information is that we don't want to generate the code to record it
for every index or slice operation. Devon pointed out a few runtime
routines that can generate the message, but most of the time they are
bypassed in favor of generated code, and a pending CL will eliminate
them entirely. So every byte we save in the generated code for x[i] is
saved on every x[i] in your program.
If some day we get to the point where the compiler was discarding
bounds checks for, say, 99% of index or slice operations, then a case
might be made that it is cheap enough to record the information for
the remaining operations. But that's not where we are today.
Russ