-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
give more information in StringIndexError #36054
Conversation
Bikeshed over Perhaps |
base/strings/string.jl
Outdated
@@ -11,6 +11,15 @@ struct StringIndexError <: Exception | |||
end | |||
@noinline string_index_err(s::AbstractString, i::Integer) = | |||
throw(StringIndexError(s, Int(i))) | |||
function Base.showerror(io::IO, exc::StringIndexError) | |||
s = exc.string | |||
i = thisind(s, exc.index) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
StringIndexError
is exported and may be (mis)used by user code — maybe defensively check for exc.index < firstindex(s) && return invoke(showerror, Tuple{IO, Any}, io, exc)
before doing something that may throw?
I like that version fine, it's certainly clearer to me than |
Oh but "previous valid index" reads more naturally than "valid previous index". There's some rule about how adjectives get sorted in English and "valid previous index" violates them (in some way that I only know intuitively, I have no idea what the rules actually are, just that they exist). |
Same for "valid next index" which would be "next valid index" instead. |
We use pairs to connect indices to values in some cases; it could be |
Yeah, I thought about this too but decided on this to sort of emphasise the "valid |
Did some tweaks based on comments |
Before
Now