You can either print the error yourself or look at what the task resolves to:
function start_async_print()
start_time = time()
t = @async try
do_some_work(10)
catch err
bt = catch_backtrace()
println()
showerror(stderr, err, bt)
end
while !istaskdone(t)
println("start() is waiting for do_some_work() to be done")
sleep(1)
end
end
function start_async_throw()
start_time = time()
t = do_some_work(10)
while !istaskdone(t)
println("start() is waiting for do_some_work() to be done")
sleep(1)
end
wait(t) # or fetch(t)
end
gives
julia> start_async_print()
start() is waiting for do_some_work() to be done
UndefVarError: b not defined
Stacktrace:
[1] do_some_work at ./untitled-8822451613b5304f5f50924dadde5d27:6 [inlined]
[2] (::getfield(Main, Symbol("##27#28")))() at ./task.jl:259
julia> start_async_throw()
ERROR: UndefVarError: b not defined
Stacktrace:
[1] do_some_work at ./untitled-8822451613b5304f5f50924dadde5d27:6 [inlined]
[2] start_async_throw() at ./untitled-8822451613b5304f5f50924dadde5d27:33
[3] top-level scope at none:0
The wait
/fetch
approach obviously doesn’t work very well when you don’t want to block.