I am stupid… @jpsamaroo, your first answer was exactly what I wanted! I just didn’t see it! I changed the initial code I posted, so it handles the errors:
using Distributed
@everywhere begin
function worker()
worker_id = myid()
println("This is a test print from worker ", string(worker_id))
error("This is a thrown, uncatched error from worker"*string(worker_id))
println("This is another test print from worker ", string(worker_id))
end
end
function main()
current_workers = workers()
futures = Array{Future}(undef, length(current_workers))
for i in 1:length(current_workers)
futures[i] = @spawnat i worker()
end
sleep(0.01)
for f in futures
try
fetch(f)
catch ex
println(ex)
end
end
end
main()
The output of 3 workers is
From worker 2: This is a test print from worker 2
From worker 3: This is a test print from worker 3
From worker 4: This is a test print from worker 4
RemoteException(2, CapturedException(ErrorException(“This is a thrown, uncatched error from worker2”), Any[(error at error.jl:33, 1), (worker at parallel_stdio.jl:19, 1), (#59 at macros.jl:73, 1), (#109 at process_messages.jl:265, 1), (run_work_thunk at process_messages.jl:56, 1), (run_work_thunk at process_messages.jl:65, 1), (#102 at task.jl:259, 1)]))
RemoteException(3, CapturedException(ErrorException(“This is a thrown, uncatched error from worker3”), Any[(error at error.jl:33, 1), (worker at parallel_stdio.jl:19, 1), (#59 at macros.jl:73, 1), (#109 at process_messages.jl:265, 1), (run_work_thunk at process_messages.jl:56, 1), (run_work_thunk at process_messages.jl:65, 1), (#102 at task.jl:259, 1)]))
RemoteException(4, CapturedException(ErrorException(“This is a thrown, uncatched error from worker4”), Any[(error at error.jl:33, 1), (worker at parallel_stdio.jl:19, 1), (#59 at macros.jl:73, 1), (#109 at process_messages.jl:265, 1), (run_work_thunk at process_messages.jl:56, 1), (run_work_thunk at process_messages.jl:65, 1), (#102 at task.jl:259, 1)]))
Just one question remaining: When I run this with no additional workers, it does not print the error message. I get this result:
This is a test print from worker 1
What is the reason for this?