Skip to content

Commit

Permalink
Merge pull request #17 from JuliaDebug/teh/rethrow
Browse files Browse the repository at this point in the history
Handle rethrow
  • Loading branch information
timholy committed Feb 12, 2019
2 parents 71f19fb + 5d986fb commit 3e5c4ab
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/interpret.jl
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ function evaluate_call!(stack, frame::JuliaStackFrame, call_expr::Expr, pc)
fargs = collect_args(frame, call_expr)
if fargs[1] === Core.eval
return Core.eval(fargs[2], fargs[3]) # not a builtin, but worth treating specially
elseif fargs[1] === Base.rethrow
err = length(fargs) > 1 ? fargs[2] : frame.last_exception[]
throw(err)
end
framecode, lenv = get_call_framecode(fargs, frame.code, pc.next_stmt)
if lenv === nothing
Expand Down
58 changes: 58 additions & 0 deletions test/interpret.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,64 @@ end
fkw(x::Int8; y=0, z="hello") = y
@test @interpret(fkw(Int8(1); y=22, z="world")) == fkw(Int8(1); y=22, z="world")

# Throwing exceptions across frames
function f_exc_inner()
error("inner")
end

f_exc_inner2() = f_exc_inner()

const caught = Ref(false)
function f_exc_outer1()
try
f_exc_inner()
catch err # with an explicit err capture
caught[] = true
rethrow(err)
end
end

function f_exc_outer2()
try
f_exc_inner()
catch # implicit err capture
caught[] = true
rethrow()
end
end

function f_exc_outer3(f)
try
f()
catch err
return err
end
end

@test !caught[]
ret = @interpret f_exc_outer3(f_exc_outer1)
@test ret == ErrorException("inner")
@test caught[]

caught[] = false
ret = @interpret f_exc_outer3(f_exc_outer2)
@test ret == ErrorException("inner")
@test caught[]

caught[] = false
ret = @interpret f_exc_outer3(f_exc_inner2)
@test ret == ErrorException("inner")
@test !caught[]


stc = try f_exc_outer1() catch
stacktrace(catch_backtrace())
end
sti = try @interpret(f_exc_outer1()) catch
stacktrace(catch_backtrace())
end
@test_broken stc == sti

# issue #3
@test @interpret(joinpath("/home/julia/base", "sysimg.jl")) == "/home/julia/base/sysimg.jl"
@test @interpret(10.0^4) == 10.0^4
Expand Down

0 comments on commit 3e5c4ab

Please sign in to comment.