Get error string contents

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

For example:

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

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.

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

julia> KeyError("a").key

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

1 Like

Also recently found:

julia> fieldnames(KeyError)

This file is another good reference on displaying errors.