Skip to content

Commit

Permalink
only break if we are throwing an uncaught exception (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC authored Mar 4, 2019
1 parent 9c5fd8f commit 28af3b3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
10 changes: 6 additions & 4 deletions src/interpret.jl
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,11 @@ function step_expr!(stack, frame, istoplevel::Bool=false)
end

function handle_err(stack, frame, pc, err)
if !isempty(frame.exception_frames)
# Exception caught
frame.last_exception[] = err
return JuliaProgramCounter(frame.exception_frames[end])
end
if break_on_error[]
frame.pc[] = pc
push!(stack, frame)
Expand All @@ -499,12 +504,9 @@ function handle_err(stack, frame, pc, err)
hasmethod(err.f, arg_types) &&
!hasmethod(err.f, arg_types, world = err.world))
@warn "likely failure to return to toplevel, try JuliaInterpreter.split_expressions"
rethrow(err)
end
end
isempty(frame.exception_frames) && rethrow(err)
frame.last_exception[] = err
return JuliaProgramCounter(frame.exception_frames[end])
rethrow(err)
end

"""
Expand Down
29 changes: 19 additions & 10 deletions test/breakpoints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,23 @@ end
remove()

# break on error
inner(x) = error("oops")
outer() = inner(1)
JuliaInterpreter.break_on_error[] = true
stack = JuliaStackFrame[]
frame = JuliaInterpreter.enter_call(outer)
bp = JuliaInterpreter.finish_and_return!(stack, frame)
@test bp.err == ErrorException("oops")
@test length(stack) >= 2
@test stack[1].code.scope.name == :outer
@test stack[2].code.scope.name == :inner
try
JuliaInterpreter.break_on_error[] = true

inner(x) = error("oops")
outer() = inner(1)
stack = JuliaStackFrame[]
frame = JuliaInterpreter.enter_call(outer)
bp = JuliaInterpreter.finish_and_return!(stack, frame)
@test bp.err == ErrorException("oops")
@test length(stack) >= 2
@test stack[1].code.scope.name == :outer
@test stack[2].code.scope.name == :inner

f_catch() = try error(); catch; return 2; end
@test @interpret f_catch() == 2

finally
JuliaInterpreter.break_on_error[] = false
end
end

0 comments on commit 28af3b3

Please sign in to comment.