# Get error string contents

**URL:** <https://discourse.julialang.org/t/get-error-string-contents/27432>\
**Category:** General Usage\
**Created:** [August 11, 2019, 10:48pm UTC](https://discourse.julialang.org/t/get-error-string-contents/27432 "2019-08-11T22:48:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![milesf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/milesf/32/9289_2.png) [@milesf](https://discourse.julialang.org/u/milesf)\
**Post date:** [August 11, 2019, 10:48pm UTC](https://discourse.julialang.org/t/get-error-string-contents/27432/1 "2019-08-11T22:48:45Z")

</div>

How do you access to the error string payload in addition to the error type?

For example:

```julia
d = Dict()
e = try
  a = parse(Float64, d["a"])
catch error
  error
end

```

For convenience in REPL, `e` is set to the error, which is `KeyError("a")`.

I can get the error type of `KeyError` with `typeof(e)`, but I don’t know how to get the string payload of `"a"` from this error.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [August 12, 2019, 12:37am UTC](https://discourse.julialang.org/t/get-error-string-contents/27432/2 "2019-08-12T00:37:21Z")

</div>

> [@milesf](#):
>
> I can get the error type of `KeyError` with `typeof(e)` , but I don’t know how to get the string payload of `"a"` from this error.

```julia
julia> dump(KeyError("a"))
KeyError
  key: String "a"

julia> KeyError("a").key
"a"

```

Note that different exception types can have different `struct` field names, however.

---

<div class="post-metadata">

**Author:** ![milesf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/milesf/32/9289_2.png) [@milesf](https://discourse.julialang.org/u/milesf)\
**Post date:** [August 12, 2019, 12:42am UTC](https://discourse.julialang.org/t/get-error-string-contents/27432/3 "2019-08-12T00:42:34Z")

</div>

Also recently found:

```julia
julia> fieldnames(KeyError)
(:key,)

```

This file is another good reference on displaying errors.  
[https://github.com/JuliaLang/julia/blob/a18ab97f74dce6f9d116690bff89ddd73c0ce308/base/errorshow.jl#L138](https://github.com/JuliaLang/julia/blob/a18ab97f74dce6f9d116690bff89ddd73c0ce308/base/errorshow.jl#L138)
