If I want to attach additional information to an exception, e.g. I have a vector of some structs and do something with each. For one, there is an exception, and it would be helpful if I know from which.
Maybe like this:
julia> try
try
Int64(NaN)
catch e
error("Error from struct 1")
end
catch e2
error("Error 2")
end
ERROR: "Error 2"
Stacktrace:
[1] top-level scope
@ REPL[9]:8
caused by: "Error from struct 1"
Stacktrace:
[1] top-level scope
@ REPL[9]:5
caused by: InexactError: Int64(NaN)
Stacktrace:
[1] Int64(x::Float64)
@ Base .\float.jl:900
[2] top-level scope
@ REPL[9]:3
Is there an idiomatic way for this?
Mixing logging and exceptions is an option too:
try
Int64(NaN)
catch e
@debug("Error from struct 1")
throw(e)
end