# Function Definition Precedence

**URL:** https://discourse.julialang.org/t/function-definition-precedence/26057
**Category:** New to Julia
**Created:** [July 5, 2019, 8:50pm UTC](https://discourse.julialang.org/t/function-definition-precedence/26057 "2019-07-05T20:50:45Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![stene](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stene/32/26044_2.png) [@stene](https://discourse.julialang.org/u/stene)
#### Post date: [July 5, 2019, 8:50pm UTC](https://discourse.julialang.org/t/function-definition-precedence/26057/1 "2019-07-05T20:50:45Z")

</div>

How do function definition precedence work?

```julia
julia> function f()
           begin
               try
                   return 1
               finally
                   return 2
               end
           end
       end
f (generic function with 2 methods)

julia> f()
2

julia> function f(x::Any = "test")
           begin
               try
                   return 3
               finally
                   return 4
               end
           end
       end
f (generic function with 2 methods)

**julia>** f()

4

julia> function f()
           begin
               try
                   return 1
               finally
                   return 2
               end
           end
       end
f (generic function with 2 methods)

julia> f()
2

```

---

<div class="post-metadata">

### Author: ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)
#### Post date: [July 5, 2019, 9:04pm UTC](https://discourse.julialang.org/t/function-definition-precedence/26057/2 "2019-07-05T21:04:22Z")

</div>

this may help [Essentials · The Julia Language](https://docs.julialang.org/en/v1.2-dev/base/base/#try)  
`finally` is always run, even with `return` in the `try` part.

---

<div class="post-metadata">

### Author: ![pixel27](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pixel27/32/8902_2.png) [@pixel27](https://discourse.julialang.org/u/pixel27)
#### Post date: [July 6, 2019, 9:53pm UTC](https://discourse.julialang.org/t/function-definition-precedence/26057/3 "2019-07-06T21:53:04Z")

</div>

When you define:

```julia
function f(x::Any = "test")
  begin
      try
          return 3
      finally
          return 4
      end
  end
end

```

It actually defines 2 methods, one that takes an argument and one that doesn’t:

```julia
julia> methods(f)

# 2 methods for generic function "f":
[1] f() in Main at none:2
[2] f(x) in Main at none:2

```

So when you define f() again it overwrites the f method that takes no parameters.
