Skip to content

Tasks and exceptions #12485

Closed
Closed

Description

Working with exceptions in the presence of tasks can be a little frustrating. Two concrete issues I encountered:

julia> t = @schedule try
       while true; sleep(1); end
       catch e
       isa(e,InterruptException) || rethrow(e)
       end
Task (waiting) @0x00000001116c6cb0

julia> try
       error("You will never see me")
       catch e
       rethrow(e)
       finally
       Base.throwto(t,InterruptException)
       end
ERROR: InterruptException
 in throwto at ./task.jl:29
 in anonymous at ./no file:6

This is because exception in transit is not task local.

The other problem is that stack traces are pretty bad when waiting on a task:

julia> foo() = error("Foo")
foo (generic function with 1 method)

julia> foo()
ERROR: Foo
 in foo at ./none:1

julia> wait(@schedule foo())
ERROR: Foo
 in yieldto at ./task.jl:24
 in wait at ./task.jl:313
 in wait at ./task.jl:228
 in wait at ./task.jl:61

The backtrace from the task is not shown anywhere. Ideally it would be displayed somehow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

bugIndicates an unexpected problem or unintended behaviorerror handlingHandling of exceptions by Julia or the user

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions