I want to ensure that the MethodError
is raised by by a function in my package, and not downstream.
For example here’s one way:
julia> e = MethodError(sin, "a")
MethodError(sin, "a", 0xffffffffffffffff)
julia> e.f == sin
true
but I’m not sure if this is too internal to be used in a package. Another way is to capture the error string and process it to extract the function, eg something along these lines:
julia> s = try
sin("a")
catch e
io = IOBuffer()
showerror(io, e)
s = String(take!(io))
split(s, '\n')[1]
end
"MethodError: no method matching sin(::String)"
julia> startswith(s, "MethodError: no method matching sin")
true
This seems clunky and might break if the error string is changed at any point.
Is there a better way to achieve this?