Skip to content

Commit

Permalink
only break if error would propagate to user (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC authored Mar 7, 2019
1 parent bf14122 commit d5fbe82
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/interpret.jl
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,21 @@ end

function handle_err(stack, frame, pc, err)
if break_on_error[]
frame.pc[] = pc
push!(stack, frame)
return BreakpointRef(frame.code, pc, err)
# See if the current frame or a frame in the stack will catch this exception,
# otherwise this exception would have been thrown to the user and we should
# return a breakpoint
exception_caught = false
for fr in Iterators.flatten(((frame,), (Iterators.reverse(stack))))
if !isempty(fr.exception_frames)
exception_caught = true
break
end
end
if !exception_caught
frame.pc[] = pc
push!(stack, frame)
return BreakpointRef(frame.code, pc, err)
end
end
# Check for world age errors, which generally indicate a failure to go back to toplevel
if isa(err, MethodError)
Expand Down
16 changes: 16 additions & 0 deletions test/breakpoints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,22 @@ end
@test length(stack) >= 2
@test stack[1].code.scope.name == :outer
@test stack[2].code.scope.name == :inner

# Don't break on caught exceptions
function f_exc_outer()
try
f_exc_inner()
catch err
return err
end
end
function f_exc_inner()
error()
end
stack = JuliaStackFrame[];
frame = JuliaInterpreter.enter_call(f_exc_outer);
v = JuliaInterpreter.finish_and_return!(stack, frame)
@test v isa ErrorException
finally
JuliaInterpreter.break_on_error[] = false
end
Expand Down

0 comments on commit d5fbe82

Please sign in to comment.