Scoping rules try-catch inside a while loop

I can’t reproduce the UndefVarError. It either works or throws an ERROR: Fail!.

compute(x,y) = rand() < 0.9 ? error("Ouch!") : x+y

function f(x, y)
    success = false
    stop = 0
    local z # z is a vector whose dimension is not known
    while !success && (stop < 10)
        try
            z = compute(x, y)
            success = true
        catch e
            @warn "Retry..."
            stop += 1
        end
    end

    if stop == 10
        error("Fail!")
    end

    return z
end

julia> f(2,3)
┌ Warning: Retry...
└ @ Main ~/scratch/foo.jl:13
┌ Warning: Retry...
└ @ Main ~/scratch/foo.jl:13
┌ Warning: Retry...
└ @ Main ~/scratch/foo.jl:13
┌ Warning: Retry...
└ @ Main ~/scratch/foo.jl:13
5

julia> f(2,3)
┌ Warning: Retry...
└ @ Main ~/scratch/foo.jl:13
┌ Warning: Retry...
└ @ Main ~/scratch/foo.jl:13
┌ Warning: Retry...
└ @ Main ~/scratch/foo.jl:13
┌ Warning: Retry...
└ @ Main ~/scratch/foo.jl:13
┌ Warning: Retry...
└ @ Main ~/scratch/foo.jl:13
┌ Warning: Retry...
└ @ Main ~/scratch/foo.jl:13
┌ Warning: Retry...
└ @ Main ~/scratch/foo.jl:13
┌ Warning: Retry...
└ @ Main ~/scratch/foo.jl:13
┌ Warning: Retry...
└ @ Main ~/scratch/foo.jl:13
┌ Warning: Retry...
└ @ Main ~/scratch/foo.jl:13
ERROR: Fail!
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:44
 [2] f(x::Int64, y::Int64)
   @ Main ~/scratch/foo.jl:19
 [3] top-level scope
   @ REPL[2]:1

Which version of julia are you running?