# \`error\` vs \`throw(ArgumentError(...))\`

**URL:** <https://discourse.julialang.org/t/error-vs-throw-argumenterror/18915>\
**Category:** General Usage\
**Tags:** error-message\
**Created:** [December 21, 2018, 10:48pm UTC](https://discourse.julialang.org/t/error-vs-throw-argumenterror/18915 "2018-12-21T22:48:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)\
**Post date:** [December 21, 2018, 10:48pm UTC](https://discourse.julialang.org/t/error-vs-throw-argumenterror/18915/1 "2018-12-21T22:48:57Z")

</div>

Hi guys!

I just want to know the best practice here. In my package, if I see an error related to an wrong input argument (like using -1 for orbit eccentricity), then is it better to use `error` ou `throw(ArgumentError(...))` to the user? I asked on slack but I got mixed results.

---

<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:** [December 22, 2018, 1:23pm UTC](https://discourse.julialang.org/t/error-vs-throw-argumenterror/18915/2 "2018-12-22T13:23:40Z")

</div>

I would use `ArgumentError` or `DomainError`. Being more specific is just informative to the user (as neither of these errors would be something that you would routinely catch). Cf

> **[GitHub - jw3126/ArgCheck.jl: Package for checking function arguments](https://github.com/jw3126/ArgCheck.jl)**
>
> Package for checking function arguments. Contribute to jw3126/ArgCheck.jl development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)\
**Post date:** [December 22, 2018, 3:49pm UTC](https://discourse.julialang.org/t/error-vs-throw-argumenterror/18915/3 "2018-12-22T15:49:31Z")

</div>

Being more specific also allows you to write tests with `@test_throws` that don’t just pass spuriously if the same type of error is thrown in some other part of the code under test.

---

<div class="post-metadata">

**Author:** ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)\
**Post date:** [December 22, 2018, 5:36pm UTC](https://discourse.julialang.org/t/error-vs-throw-argumenterror/18915/4 "2018-12-22T17:36:00Z")

</div>

Excellent arguments! Thanks guys, I will change all the `errors` to some more informative.
