In an API I ask the user to define custom types and also methods for them for a collection of functions. When this is not done, a
MethodError is thrown automatically since nothing is defined, but I wonder if I could make this informative. Eg
using DocStringExtensions """ $SIGNATURES Define this to simulate values from your model. """ function simulate(model) warn("You need to define `simulate` for your model type.") throw(MethodError(simulate, model)) end
documents the signature automatically (DRY), and gives an informative warning:
julia> simulate(1.0) WARNING: You need to define `simulate` for your model type. ERROR: MethodError: no method matching simulate(::Float64) Closest candidates are: simulate(::Any) at REPL:2 Stacktrace:  simulate(::Float64) at ./REPL:3
I wonder that the best practice is. Should I throw the
MethodError, or just
error with the same message?