Behavior of threaded loop with BoundsError

function f1()
    x = zeros(10000)
    Threads.@threads for i in 1:100000 #typo causes BoundsError
        x[i] = 2.0 * i
    end
    return x
end

f1()

returns x with values from 2 up to 20000 and prints Error thrown in threaded loop on thread 0: BoundsError(a=Array{Float64, (10000,)}[2, 4, 6, ...

But:

function f2()
    x = zeros(10000)
    for i in 1:100000 #typo causes BoundsError
        x[i] = 2.0 * i
    end
    return x
end

f2()

simply throws the error and does not return.

Is there a rationale behind this behavior or is this a bug? My thinking is that the behavior should be identical.

My two cents on what’s going on here:
Each thread gets its own part of the loop, only the thread that has the out of bounds part errors, but all other threads are doing their work. The main thread didn’t encounter an error and worker threads don’t halt execution, I. E. It proceeds to return x. In the second case it was the main thread that encounters the bounds error and halts execution thus not returning anything.

Not sure if that’s entirely correct or wanted behavior bit with the way threading is working now that seems to be what’s going on.