# What's the differences between \`throw(ArgumentError(""))\` and \`return throw(ArgumentError("")\`)

**URL:** https://discourse.julialang.org/t/whats-the-differences-between-throw-argumenterror-and-return-throw-argumenterror/51909
**Category:** General Usage
**Tags:** question, exception
**Created:** [December 16, 2020, 5:43am UTC](https://discourse.julialang.org/t/whats-the-differences-between-throw-argumenterror-and-return-throw-argumenterror/51909 "2020-12-16T05:43:20Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![baddate](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baddate/32/19017_2.png) [@baddate](https://discourse.julialang.org/u/baddate)
#### Post date: [December 16, 2020, 5:43am UTC](https://discourse.julialang.org/t/whats-the-differences-between-throw-argumenterror-and-return-throw-argumenterror/51909/1 "2020-12-16T05:43:20Z")

</div>

i wrote a function that will throw an ArgumentError if it occurred any exception.  
but i have a question about throwing an error:  
i can use `throw()` directly, also i can use the `return` keyword.  
Is there any difference?

```julia
function distance(a, b)
    if length(a) != length(b)
        return throw(ArgumentError(""))
    end
    dist = 0
    i = 1
    while i <= length(a)
        if a[i] != b[i]
            dist += 1
        end
        i += 1
    end
    return dist
end

```

---

<div class="post-metadata">

### Author: ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)
#### Post date: [December 16, 2020, 11:23am UTC](https://discourse.julialang.org/t/whats-the-differences-between-throw-argumenterror-and-return-throw-argumenterror/51909/2 "2020-12-16T11:23:05Z")

</div>

Here the `return` keyword is useless and misleading. The following:

```julia
function f()
    return throw(...)
end

```

is a bit like

```julia
function f()
    return sin("abc") # Some invalid code that throws an error
end

```

In both cases, Julia is supposed to evaluate an expression and return the result. But in both cases, an exception is thrown during evaluation, so the execution is stopped before the function returns anything.
