# Fallback method error reporting

**URL:** <https://discourse.julialang.org/t/fallback-method-error-reporting/8473>\
**Category:** General Usage\
**Tags:** question\
**Created:** [January 19, 2018, 1:19pm UTC](https://discourse.julialang.org/t/fallback-method-error-reporting/8473 "2018-01-19T13:19:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [January 19, 2018, 1:19pm UTC](https://discourse.julialang.org/t/fallback-method-error-reporting/8473/1 "2018-01-19T13:19:16Z")

</div>

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

```julia
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
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[39]:2
Stacktrace:
 [1] simulate(::Float64) at ./REPL[39]:3

```

I wonder that the best practice is. Should I throw the `MethodError`, or just `error` with the same message?

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [January 19, 2018, 1:21pm UTC](https://discourse.julialang.org/t/fallback-method-error-reporting/8473/2 "2018-01-19T13:21:27Z")

</div>

Related

[https://github.com/JuliaLang/julia/pull/24299](https://github.com/JuliaLang/julia/pull/24299)

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [January 19, 2018, 1:46pm UTC](https://discourse.julialang.org/t/fallback-method-error-reporting/8473/3 "2018-01-19T13:46:42Z")

</div>

Thanks! It would be great to have that, but that’s probably post-`v1.0`. In the meantime, I ended up using

```julia
using MacroTools
macro no_method_info(ex)
    @capture(ex, f_(args__)) || error("Expected a function name with arguments")
    msg = "You need to define `$(string(f))` with this model type."
    esc_f = esc(f)
    esc_args = map(esc, args)
    quote
        function $esc_f($(esc_args...))
            info($msg)
            throw(MethodError($esc_f,
                              Tuple{$(map(e -> :(typeof($e)), esc_args)...)}))
        end
    end
end

```

**EDIT** : made arguments into a `Tuple` for `MethodError`.
