Skip to content

Commit

Permalink
Replace trivial uses of rethrow(exc) with rethrow() (#29794)
Browse files Browse the repository at this point in the history
In all these cases we're merely rethrowing the existing exception, so it
seems simpler and clearer just to use `rethrow()` without arguments.

Previously it wasn't reliable to use `rethrow()` like this but the exception
stack system from #29794 has fixed those problems.
  • Loading branch information
c42f authored Oct 29, 2018
1 parent b84fe52 commit 453a7dd
Show file tree
Hide file tree
Showing 39 changed files with 80 additions and 80 deletions.
2 changes: 1 addition & 1 deletion base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ function isassigned(a::AbstractArray, i::Integer...)
if isa(e, BoundsError) || isa(e, UndefRefError)
return false
else
rethrow(e)
rethrow()
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions base/abstractdict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ function filter(f, d::AbstractDict)
end
end
else
rethrow(e)
rethrow()
end
end
return df
Expand Down Expand Up @@ -550,12 +550,12 @@ end
function IdDict(kv)
try
dict_with_eltype((K, V) -> IdDict{K, V}, kv, eltype(kv))
catch e
catch
if !applicable(iterate, kv) || !all(x->isa(x,Union{Tuple,Pair}),kv)
throw(ArgumentError(
"IdDict(kv): kv needs to be an iterator of tuples or pairs"))
else
rethrow(e)
rethrow()
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion base/asyncmap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ function maptwice(wrapped_f, chnl, worker_tasks, c...)
# in asyncrun due to a closed channel.
asyncrun_excp = ex
else
rethrow(ex)
rethrow()
end
end

Expand Down
10 changes: 5 additions & 5 deletions base/channels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,9 @@ function put_unbuffered(c::Channel, v)

try
wait()
catch ex
catch
filter!(x->x!=current_task(), c.putters)
rethrow(ex)
rethrow()
end
end
taker = popfirst!(c.takers)
Expand Down Expand Up @@ -329,9 +329,9 @@ function take_unbuffered(c::Channel{T}) where T
else
return wait()::T
end
catch ex
catch
filter!(x->x!=current_task(), c.takers)
rethrow(ex)
rethrow()
end
end

Expand Down Expand Up @@ -389,7 +389,7 @@ function iterate(c::Channel, state=nothing)
if isa(e, InvalidStateException) && e.state==:closed
return nothing
else
rethrow(e)
rethrow()
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ function eval_user_input(@nospecialize(ast), show_value::Bool)
end
try
invokelatest(display, value)
catch err
catch
println(stderr, "Evaluation succeeded, but an error occurred while showing value of type ", typeof(value), ":")
rethrow(err)
rethrow()
end
println()
end
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/tfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ function _const_sizeof(@nospecialize(x))
# Might return
# "argument is an abstract type; size is indeterminate" or
# "type does not have a fixed size"
isa(ex, ErrorException) || rethrow(ex)
isa(ex, ErrorException) || rethrow()
return Int
end
return Const(size)
Expand Down
4 changes: 2 additions & 2 deletions base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ Dict(ps::Pair...) = Dict(ps)
function Dict(kv)
try
dict_with_eltype((K, V) -> Dict{K, V}, kv, eltype(kv))
catch e
catch
if !isiterable(typeof(kv)) || !all(x->isa(x,Union{Tuple,Pair}),kv)
throw(ArgumentError("Dict(kv): kv needs to be an iterator of tuples or pairs"))
else
rethrow(e)
rethrow()
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions base/error.jl
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,11 @@ function retry(f::Function; delays=ExponentialBackOff(), check=nothing)
try
return f(args...; kwargs...)
catch e
y === nothing && rethrow(e)
y === nothing && rethrow()
if check !== nothing
result = check(state, e)
state, retry_or_not = length(result) == 2 ? result : (state, result)
retry_or_not || rethrow(e)
retry_or_not || rethrow()
end
end
sleep(delay)
Expand Down
8 changes: 4 additions & 4 deletions base/event.jl
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ end
function try_yieldto(undo, reftask::Ref{Task})
try
ccall(:jl_switchto, Cvoid, (Any,), reftask)
catch e
catch
undo(reftask[])
rethrow(e)
rethrow()
end
ct = current_task()
exc = ct.exception
Expand Down Expand Up @@ -315,7 +315,7 @@ function AsyncCondition(cb::Function)
wait(async)
true
catch exc # ignore possible exception on close()
isa(exc, EOFError) || rethrow(exc)
isa(exc, EOFError) || rethrow()
end
success && cb(async)
end
Expand Down Expand Up @@ -469,7 +469,7 @@ function Timer(cb::Function, timeout::Real; interval::Real = 0.0)
wait(t)
true
catch exc # ignore possible exception on close()
isa(exc, EOFError) || rethrow(exc)
isa(exc, EOFError) || rethrow()
false
end
success && cb(t)
Expand Down
2 changes: 1 addition & 1 deletion base/initdefs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ end
function current_project()
dir = try pwd()
catch err
err isa IOError || rethrow(err)
err isa IOError || rethrow()
return nothing
end
return current_project(dir)
Expand Down
6 changes: 3 additions & 3 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ function create_expr_cache(input::String, output::String, concrete_deps::typeof(
try
Base.include(Base.__toplevel__, $(repr(abspath(input))))
catch ex
Base.precompilableerror(ex) || Base.rethrow(ex)
Base.precompilableerror(ex) || Base.rethrow()
Base.@debug "Aborting `createexprcache'" exception=(Base.ErrorException("Declaration of __precompile__(false) not allowed"), Base.catch_backtrace())
Base.exit(125) # we define status = 125 means PrecompileableError
end\0""")
Expand All @@ -1145,10 +1145,10 @@ function create_expr_cache(input::String, output::String, concrete_deps::typeof(
end
write(in, "ccall(:jl_set_module_uuid, Cvoid, (Any, NTuple{2, UInt64}), Base.__toplevel__, (0, 0))\0")
close(in)
catch ex
catch
close(in)
process_running(io) && Timer(t -> kill(io), 5.0) # wait a short time before killing the process to give it a chance to clean up on its own first
rethrow(ex)
rethrow()
end
return io
end
Expand Down
4 changes: 2 additions & 2 deletions base/process.jl
Original file line number Diff line number Diff line change
Expand Up @@ -615,9 +615,9 @@ function open(f::Function, cmds::AbstractCmd, args...)
P = open(cmds, args...)
ret = try
f(P)
catch e
catch
kill(P)
rethrow(e)
rethrow()
finally
close(P.in)
end
Expand Down
4 changes: 2 additions & 2 deletions base/rational.jl
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ function rationalize(::Type{T}, x::AbstractFloat, tol::Real) where T<:Integer
p, pp = np, p
q, qq = nq, q
catch e
isa(e,InexactError) || isa(e,OverflowError) || rethrow(e)
isa(e,InexactError) || isa(e,OverflowError) || rethrow()
return p // q
end

Expand All @@ -180,7 +180,7 @@ function rationalize(::Type{T}, x::AbstractFloat, tol::Real) where T<:Integer
nq = checked_add(checked_mul(ia,q),qq)
return np // nq
catch e
isa(e,InexactError) || isa(e,OverflowError) || rethrow(e)
isa(e,InexactError) || isa(e,OverflowError) || rethrow()
return p // q
end
end
Expand Down
8 changes: 4 additions & 4 deletions base/stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -596,15 +596,15 @@ function link_pipe!(read_end::PipeEndpoint, reader_supports_async::Bool,
try
try
open_pipe!(read_end, rd, true, false)
catch e
catch
close_pipe_sync(rd)
rethrow(e)
rethrow()
end
read_end.status = StatusOpen
open_pipe!(write_end, wr, false, true)
catch e
catch
close_pipe_sync(wr)
rethrow(e)
rethrow()
end
write_end.status = StatusOpen
nothing
Expand Down
6 changes: 3 additions & 3 deletions base/task.jl
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ function sync_end(refs)
for r in refs
try
wait(r)
catch ex
catch
if !isa(r, Task) || (isa(r, Task) && !istaskfailed(r))
rethrow(ex)
rethrow()
end
finally
if isa(r, Task) && istaskfailed(r)
Expand Down Expand Up @@ -316,7 +316,7 @@ function task_done_hook(t::Task)
active_repl_backend.in_eval
throwto(active_repl_backend.backend_task, e)
else
rethrow(e)
rethrow()
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions base/weakkeydict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ WeakKeyDict(ps::Pair...) = WeakKeyDict{Any,Any}(ps)
function WeakKeyDict(kv)
try
Base.dict_with_eltype((K, V) -> WeakKeyDict{K, V}, kv, eltype(kv))
catch e
catch
if !isiterable(typeof(kv)) || !all(x->isa(x,Union{Tuple,Pair}),kv)
throw(ArgumentError("WeakKeyDict(kv): kv needs to be an iterator of tuples or pairs"))
else
rethrow(e)
rethrow()
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions contrib/generate_precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ function generate_precompile_statements()
statement == "precompile(Tuple{typeof(Base.show), Base.IOContext{Base.TTY}, Type{Vararg{Any, N} where N}})" && continue
try
Base.include_string(PrecompileStagingArea, statement)
catch ex
catch
@error "Failed to precompile $statement"
rethrow(ex)
rethrow()
end
end
print(" $(length(statements)) generated in ")
Expand Down
4 changes: 2 additions & 2 deletions stdlib/DelimitedFiles/src/DelimitedFiles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ function readdlm_string(sbuff::String, dlm::AbstractChar, T::Type, eol::Abstract
if isa(ex, TypeError) && (ex.func == :store_cell)
T = ex.expected
else
rethrow(ex)
rethrow()
end
offset_handler = (dims === nothing) ? DLMOffsets(sbuff) : DLMStore(T, dims, has_header, sbuff, auto, eol)
end
Expand Down Expand Up @@ -713,7 +713,7 @@ function dlm_parse(dbuff::String, eol::D, dlm::D, qchar::D, cchar::D,
end
catch ex
if isa(ex, TypeError) && (ex.func == :store_cell)
rethrow(ex)
rethrow()
else
error("at row $(nrows+1), column $col : $ex)")
end
Expand Down
6 changes: 3 additions & 3 deletions stdlib/Distributed/src/cluster.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function exec_conn_func(w::Worker)
f()
catch e
w.conn_func = () -> throw(e)
rethrow(e)
rethrow()
end
nothing
end
Expand Down Expand Up @@ -505,9 +505,9 @@ function create_worker(manager, wconfig)
local r_s, w_s
try
(r_s, w_s) = connect(manager, w.id, wconfig)
catch e
catch
deregister_worker(w.id)
rethrow(e)
rethrow()
end

w = Worker(w.id, r_s, w_s, manager; config=wconfig)
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Distributed/src/clusterserialize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ function serialize_global_from_main(s::ClusterSerializer, sym)
if isa(ex, ErrorException)
record_v = false
else
rethrow(ex)
rethrow()
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions stdlib/Distributed/src/pmap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pmap(f, c; retry_delays = zeros(3))
Example: Retry `f` only if the exception is not of type `InexactError`, with exponentially increasing
delays up to 3 times. Return a `NaN` in place for all `InexactError` occurrences.
```julia
pmap(f, c; on_error = e->(isa(e, InexactError) ? NaN : rethrow(e)), retry_delays = ExponentialBackOff(n = 3))
pmap(f, c; on_error = e->(isa(e, InexactError) ? NaN : rethrow()), retry_delays = ExponentialBackOff(n = 3))
```
"""
function pmap(f, p::AbstractWorkerPool, c; distributed=true, batch_size=1, on_error=nothing,
Expand Down Expand Up @@ -189,7 +189,7 @@ function wrap_batch(f, p, handle_errors)
if handle_errors
return Any[BatchProcessingError(b, e) for b in batch]
else
rethrow(e)
rethrow()
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Distributed/src/process_messages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ function message_handler_loop(r_stream::IO, w_stream::IO, incoming::Bool)
if (myid() == 1) && (wpid > 1)
if oldstate != W_TERMINATING
println(stderr, "Worker $wpid terminated.")
rethrow(e)
rethrow()
end
end

Expand Down
10 changes: 5 additions & 5 deletions stdlib/Distributed/test/distributed_exec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ end
pmap_args = [
(:distributed, [:default, false]),
(:batch_size, [:default,2]),
(:on_error, [:default, e -> (e.msg == "foobar" ? true : rethrow(e))]),
(:on_error, [:default, e -> (e.msg == "foobar" ? true : rethrow())]),
(:retry_delays, [:default, fill(0.001, 1000)]),
(:retry_check, [:default, (s,e) -> (s,endswith(e.msg,"foobar"))]),
]
Expand Down Expand Up @@ -552,9 +552,9 @@ function walk_args(i)

try
results_test(pmap(mapf, data; kwargs...))
catch e
catch
println("pmap executing with args : ", kwargs)
rethrow(e)
rethrow()
end

return
Expand Down Expand Up @@ -662,12 +662,12 @@ if Sys.isunix() # aka have ssh
w_in_remote = sort(remotecall_fetch(workers, p))
try
@test intersect(new_pids, w_in_remote) == new_pids
catch e
catch
print("p : $p\n")
print("newpids : $new_pids\n")
print("w_in_remote : $w_in_remote\n")
print("intersect : $(intersect(new_pids, w_in_remote))\n\n\n")
rethrow(e)
rethrow()
end
end

Expand Down
Loading

2 comments on commit 453a7dd

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily benchmark build, I will reply here when finished:

@nanosoldier runbenchmarks(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan

Please sign in to comment.