When a dictionary cannot retrieve values it shows two error types, is it making a kind of chaining or is it just inside the error message?
LoadError: KeyError: key "d" not found
When a dictionary cannot retrieve values it shows two error types, is it making a kind of chaining or is it just inside the error message?
LoadError: KeyError: key "d" not found
The LoadError
is there because the error is happening during an include
or using
(see ?LoadError
). It just prints the error that happened. Just accessing a Dict
incorrectly by itself doesn’t show LoadError
.
julia> d = Dict()
Dict{Any, Any}()
julia> d[1]
ERROR: KeyError: key 1 not found
Stacktrace:
[1] getindex(h::Dict{Any, Any}, key::Int64)
@ Base .\dict.jl:477
[2] top-level scope
@ REPL[7]:1
The KeyError
can be found as a field error
inside of the LoadError
, so there is some chaining of errors here.
julia> f = tempname()
open(f, "w") do io
write(io, "d = Dict(); d['a']")
end;
julia> global e # or e = nothing: just make sure e exists outside of the try-catch scope
try
include(f) # (or just include_string(Main, "d = Dict(); d['a']") )
catch e
end
julia> dump(e)
LoadError
file: String "(...)\\Temp\\jl_7aL81yn8zO"
line: Int64 1
error: KeyError
key: key: Char 'a'
julia> e.error
KeyError('a')