# Chaining errors

**URL:** <https://discourse.julialang.org/t/chaining-errors/122984>\
**Category:** New to Julia\
**Tags:** error, error-message\
**Created:** [November 23, 2024, 7:56am UTC](https://discourse.julialang.org/t/chaining-errors/122984 "2024-11-23T07:56:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![martin\_sanchez](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/martin_sanchez/32/207525_2.png) [@martin\_sanchez](https://discourse.julialang.org/u/martin_sanchez)\
**Post date:** [November 23, 2024, 7:56am UTC](https://discourse.julialang.org/t/chaining-errors/122984/1 "2024-11-23T07:56:27Z")

</div>

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?

```julia
LoadError: KeyError: key "d" not found

```

---

<div class="post-metadata">

**Author:** ![DanielVandH](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielvandh/32/31134_2.png) [@DanielVandH](https://discourse.julialang.org/u/DanielVandH)\
**Post date:** [November 23, 2024, 8:40am UTC](https://discourse.julialang.org/t/chaining-errors/122984/2 "2024-11-23T08:40:12Z")

</div>

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
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

```

---

<div class="post-metadata">

**Author:** ![eldee](https://avatars.discourse-cdn.com/v4/letter/e/b5a626/32.png) [@eldee](https://discourse.julialang.org/u/eldee)\
**Post date:** [November 24, 2024, 11:45am UTC](https://discourse.julialang.org/t/chaining-errors/122984/3 "2024-11-24T11:45:49Z")

</div>

> [@martin\_sanchez](#):
>
> is it making a kind of chaining or is it just inside the error message?

The `KeyError` can be found as a field `error` inside of the `LoadError`, so there is some chaining of errors here.

```julia-repl
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')

```
