# Can @pure functions throw an error?

**URL:** <https://discourse.julialang.org/t/can-pure-functions-throw-an-error/18459>\
**Category:** Internals & Design\
**Tags:** question\
**Created:** [December 8, 2018, 10:36am UTC](https://discourse.julialang.org/t/can-pure-functions-throw-an-error/18459 "2018-12-08T10:36:18Z")\
**Posts on this page:** 2\
**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:** [December 8, 2018, 10:36am UTC](https://discourse.julialang.org/t/can-pure-functions-throw-an-error/18459/1 "2018-12-08T10:36:19Z")

</div>

MWE, is this OK?

```julia
Base.@pure function key_in(key::Symbol, keys::Tuple{Vararg{Symbol}})
    for k in keys
        key ≡ k && return true
    end
    false
end

Base.@pure function remove_key(key::Symbol, keys::Tuple{Vararg{Symbol}})
    kept = Symbol[]
    key_in(key, keys) || error("Cannot drop $key which is not in $keys")
    for k in keys
        k ≡ key || push!(kept, k)
    end
    (kept..., )
end

remove_key(:a, (:a, :b, :c)) # (:b, :c)
remove_key(:a, (:b, :c)) # throws error

```

---

<div class="post-metadata">

**Author:** ![jameson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jameson/32/23_2.png) [@jameson](https://discourse.julialang.org/u/jameson)\
**Post date:** [December 17, 2018, 5:24pm UTC](https://discourse.julialang.org/t/can-pure-functions-throw-an-error/18459/2 "2018-12-17T17:24:12Z")

</div>

Probably a very bad idea, as `pure` means we can discard or duplicate side-effects, which then also means we can transform any program that might call this function into one that always throws this error at startup
