Skip to content

Commit 453a7dd

Browse files
authored
Replace trivial uses of rethrow(exc) with rethrow() (#29794)
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.
1 parent b84fe52 commit 453a7dd

39 files changed

+80
-80
lines changed

base/abstractarray.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ function isassigned(a::AbstractArray, i::Integer...)
354354
if isa(e, BoundsError) || isa(e, UndefRefError)
355355
return false
356356
else
357-
rethrow(e)
357+
rethrow()
358358
end
359359
end
360360
end

base/abstractdict.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ function filter(f, d::AbstractDict)
402402
end
403403
end
404404
else
405-
rethrow(e)
405+
rethrow()
406406
end
407407
end
408408
return df
@@ -550,12 +550,12 @@ end
550550
function IdDict(kv)
551551
try
552552
dict_with_eltype((K, V) -> IdDict{K, V}, kv, eltype(kv))
553-
catch e
553+
catch
554554
if !applicable(iterate, kv) || !all(x->isa(x,Union{Tuple,Pair}),kv)
555555
throw(ArgumentError(
556556
"IdDict(kv): kv needs to be an iterator of tuples or pairs"))
557557
else
558-
rethrow(e)
558+
rethrow()
559559
end
560560
end
561561
end

base/asyncmap.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ function maptwice(wrapped_f, chnl, worker_tasks, c...)
167167
# in asyncrun due to a closed channel.
168168
asyncrun_excp = ex
169169
else
170-
rethrow(ex)
170+
rethrow()
171171
end
172172
end
173173

base/channels.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,9 @@ function put_unbuffered(c::Channel, v)
270270

271271
try
272272
wait()
273-
catch ex
273+
catch
274274
filter!(x->x!=current_task(), c.putters)
275-
rethrow(ex)
275+
rethrow()
276276
end
277277
end
278278
taker = popfirst!(c.takers)
@@ -329,9 +329,9 @@ function take_unbuffered(c::Channel{T}) where T
329329
else
330330
return wait()::T
331331
end
332-
catch ex
332+
catch
333333
filter!(x->x!=current_task(), c.takers)
334-
rethrow(ex)
334+
rethrow()
335335
end
336336
end
337337

@@ -389,7 +389,7 @@ function iterate(c::Channel, state=nothing)
389389
if isa(e, InvalidStateException) && e.state==:closed
390390
return nothing
391391
else
392-
rethrow(e)
392+
rethrow()
393393
end
394394
end
395395
end

base/client.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ function eval_user_input(@nospecialize(ast), show_value::Bool)
122122
end
123123
try
124124
invokelatest(display, value)
125-
catch err
125+
catch
126126
println(stderr, "Evaluation succeeded, but an error occurred while showing value of type ", typeof(value), ":")
127-
rethrow(err)
127+
rethrow()
128128
end
129129
println()
130130
end

base/compiler/tfuncs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ function _const_sizeof(@nospecialize(x))
315315
# Might return
316316
# "argument is an abstract type; size is indeterminate" or
317317
# "type does not have a fixed size"
318-
isa(ex, ErrorException) || rethrow(ex)
318+
isa(ex, ErrorException) || rethrow()
319319
return Int
320320
end
321321
return Const(size)

base/dict.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,11 @@ Dict(ps::Pair...) = Dict(ps)
127127
function Dict(kv)
128128
try
129129
dict_with_eltype((K, V) -> Dict{K, V}, kv, eltype(kv))
130-
catch e
130+
catch
131131
if !isiterable(typeof(kv)) || !all(x->isa(x,Union{Tuple,Pair}),kv)
132132
throw(ArgumentError("Dict(kv): kv needs to be an iterator of tuples or pairs"))
133133
else
134-
rethrow(e)
134+
rethrow()
135135
end
136136
end
137137
end

base/error.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,11 @@ function retry(f::Function; delays=ExponentialBackOff(), check=nothing)
226226
try
227227
return f(args...; kwargs...)
228228
catch e
229-
y === nothing && rethrow(e)
229+
y === nothing && rethrow()
230230
if check !== nothing
231231
result = check(state, e)
232232
state, retry_or_not = length(result) == 2 ? result : (state, result)
233-
retry_or_not || rethrow(e)
233+
retry_or_not || rethrow()
234234
end
235235
end
236236
sleep(delay)

base/event.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,9 @@ end
185185
function try_yieldto(undo, reftask::Ref{Task})
186186
try
187187
ccall(:jl_switchto, Cvoid, (Any,), reftask)
188-
catch e
188+
catch
189189
undo(reftask[])
190-
rethrow(e)
190+
rethrow()
191191
end
192192
ct = current_task()
193193
exc = ct.exception
@@ -315,7 +315,7 @@ function AsyncCondition(cb::Function)
315315
wait(async)
316316
true
317317
catch exc # ignore possible exception on close()
318-
isa(exc, EOFError) || rethrow(exc)
318+
isa(exc, EOFError) || rethrow()
319319
end
320320
success && cb(async)
321321
end
@@ -469,7 +469,7 @@ function Timer(cb::Function, timeout::Real; interval::Real = 0.0)
469469
wait(t)
470470
true
471471
catch exc # ignore possible exception on close()
472-
isa(exc, EOFError) || rethrow(exc)
472+
isa(exc, EOFError) || rethrow()
473473
false
474474
end
475475
success && cb(t)

base/initdefs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ end
100100
function current_project()
101101
dir = try pwd()
102102
catch err
103-
err isa IOError || rethrow(err)
103+
err isa IOError || rethrow()
104104
return nothing
105105
end
106106
return current_project(dir)

base/loading.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,7 @@ function create_expr_cache(input::String, output::String, concrete_deps::typeof(
11351135
try
11361136
Base.include(Base.__toplevel__, $(repr(abspath(input))))
11371137
catch ex
1138-
Base.precompilableerror(ex) || Base.rethrow(ex)
1138+
Base.precompilableerror(ex) || Base.rethrow()
11391139
Base.@debug "Aborting `createexprcache'" exception=(Base.ErrorException("Declaration of __precompile__(false) not allowed"), Base.catch_backtrace())
11401140
Base.exit(125) # we define status = 125 means PrecompileableError
11411141
end\0""")
@@ -1145,10 +1145,10 @@ function create_expr_cache(input::String, output::String, concrete_deps::typeof(
11451145
end
11461146
write(in, "ccall(:jl_set_module_uuid, Cvoid, (Any, NTuple{2, UInt64}), Base.__toplevel__, (0, 0))\0")
11471147
close(in)
1148-
catch ex
1148+
catch
11491149
close(in)
11501150
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
1151-
rethrow(ex)
1151+
rethrow()
11521152
end
11531153
return io
11541154
end

base/process.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -615,9 +615,9 @@ function open(f::Function, cmds::AbstractCmd, args...)
615615
P = open(cmds, args...)
616616
ret = try
617617
f(P)
618-
catch e
618+
catch
619619
kill(P)
620-
rethrow(e)
620+
rethrow()
621621
finally
622622
close(P.in)
623623
end

base/rational.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ function rationalize(::Type{T}, x::AbstractFloat, tol::Real) where T<:Integer
155155
p, pp = np, p
156156
q, qq = nq, q
157157
catch e
158-
isa(e,InexactError) || isa(e,OverflowError) || rethrow(e)
158+
isa(e,InexactError) || isa(e,OverflowError) || rethrow()
159159
return p // q
160160
end
161161

@@ -180,7 +180,7 @@ function rationalize(::Type{T}, x::AbstractFloat, tol::Real) where T<:Integer
180180
nq = checked_add(checked_mul(ia,q),qq)
181181
return np // nq
182182
catch e
183-
isa(e,InexactError) || isa(e,OverflowError) || rethrow(e)
183+
isa(e,InexactError) || isa(e,OverflowError) || rethrow()
184184
return p // q
185185
end
186186
end

base/stream.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -596,15 +596,15 @@ function link_pipe!(read_end::PipeEndpoint, reader_supports_async::Bool,
596596
try
597597
try
598598
open_pipe!(read_end, rd, true, false)
599-
catch e
599+
catch
600600
close_pipe_sync(rd)
601-
rethrow(e)
601+
rethrow()
602602
end
603603
read_end.status = StatusOpen
604604
open_pipe!(write_end, wr, false, true)
605-
catch e
605+
catch
606606
close_pipe_sync(wr)
607-
rethrow(e)
607+
rethrow()
608608
end
609609
write_end.status = StatusOpen
610610
nothing

base/task.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@ function sync_end(refs)
211211
for r in refs
212212
try
213213
wait(r)
214-
catch ex
214+
catch
215215
if !isa(r, Task) || (isa(r, Task) && !istaskfailed(r))
216-
rethrow(ex)
216+
rethrow()
217217
end
218218
finally
219219
if isa(r, Task) && istaskfailed(r)
@@ -316,7 +316,7 @@ function task_done_hook(t::Task)
316316
active_repl_backend.in_eval
317317
throwto(active_repl_backend.backend_task, e)
318318
else
319-
rethrow(e)
319+
rethrow()
320320
end
321321
end
322322
end

base/weakkeydict.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ WeakKeyDict(ps::Pair...) = WeakKeyDict{Any,Any}(ps)
6060
function WeakKeyDict(kv)
6161
try
6262
Base.dict_with_eltype((K, V) -> WeakKeyDict{K, V}, kv, eltype(kv))
63-
catch e
63+
catch
6464
if !isiterable(typeof(kv)) || !all(x->isa(x,Union{Tuple,Pair}),kv)
6565
throw(ArgumentError("WeakKeyDict(kv): kv needs to be an iterator of tuples or pairs"))
6666
else
67-
rethrow(e)
67+
rethrow()
6868
end
6969
end
7070
end

contrib/generate_precompile.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ function generate_precompile_statements()
167167
statement == "precompile(Tuple{typeof(Base.show), Base.IOContext{Base.TTY}, Type{Vararg{Any, N} where N}})" && continue
168168
try
169169
Base.include_string(PrecompileStagingArea, statement)
170-
catch ex
170+
catch
171171
@error "Failed to precompile $statement"
172-
rethrow(ex)
172+
rethrow()
173173
end
174174
end
175175
print(" $(length(statements)) generated in ")

stdlib/DelimitedFiles/src/DelimitedFiles.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ function readdlm_string(sbuff::String, dlm::AbstractChar, T::Type, eol::Abstract
458458
if isa(ex, TypeError) && (ex.func == :store_cell)
459459
T = ex.expected
460460
else
461-
rethrow(ex)
461+
rethrow()
462462
end
463463
offset_handler = (dims === nothing) ? DLMOffsets(sbuff) : DLMStore(T, dims, has_header, sbuff, auto, eol)
464464
end
@@ -713,7 +713,7 @@ function dlm_parse(dbuff::String, eol::D, dlm::D, qchar::D, cchar::D,
713713
end
714714
catch ex
715715
if isa(ex, TypeError) && (ex.func == :store_cell)
716-
rethrow(ex)
716+
rethrow()
717717
else
718718
error("at row $(nrows+1), column $col : $ex)")
719719
end

stdlib/Distributed/src/cluster.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ function exec_conn_func(w::Worker)
136136
f()
137137
catch e
138138
w.conn_func = () -> throw(e)
139-
rethrow(e)
139+
rethrow()
140140
end
141141
nothing
142142
end
@@ -505,9 +505,9 @@ function create_worker(manager, wconfig)
505505
local r_s, w_s
506506
try
507507
(r_s, w_s) = connect(manager, w.id, wconfig)
508-
catch e
508+
catch
509509
deregister_worker(w.id)
510-
rethrow(e)
510+
rethrow()
511511
end
512512

513513
w = Worker(w.id, r_s, w_s, manager; config=wconfig)

stdlib/Distributed/src/clusterserialize.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ function serialize_global_from_main(s::ClusterSerializer, sym)
159159
if isa(ex, ErrorException)
160160
record_v = false
161161
else
162-
rethrow(ex)
162+
rethrow()
163163
end
164164
end
165165
end

stdlib/Distributed/src/pmap.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ pmap(f, c; retry_delays = zeros(3))
9393
Example: Retry `f` only if the exception is not of type `InexactError`, with exponentially increasing
9494
delays up to 3 times. Return a `NaN` in place for all `InexactError` occurrences.
9595
```julia
96-
pmap(f, c; on_error = e->(isa(e, InexactError) ? NaN : rethrow(e)), retry_delays = ExponentialBackOff(n = 3))
96+
pmap(f, c; on_error = e->(isa(e, InexactError) ? NaN : rethrow()), retry_delays = ExponentialBackOff(n = 3))
9797
```
9898
"""
9999
function pmap(f, p::AbstractWorkerPool, c; distributed=true, batch_size=1, on_error=nothing,
@@ -189,7 +189,7 @@ function wrap_batch(f, p, handle_errors)
189189
if handle_errors
190190
return Any[BatchProcessingError(b, e) for b in batch]
191191
else
192-
rethrow(e)
192+
rethrow()
193193
end
194194
end
195195
end

stdlib/Distributed/src/process_messages.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ function message_handler_loop(r_stream::IO, w_stream::IO, incoming::Bool)
227227
if (myid() == 1) && (wpid > 1)
228228
if oldstate != W_TERMINATING
229229
println(stderr, "Worker $wpid terminated.")
230-
rethrow(e)
230+
rethrow()
231231
end
232232
end
233233

stdlib/Distributed/test/distributed_exec.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ end
492492
pmap_args = [
493493
(:distributed, [:default, false]),
494494
(:batch_size, [:default,2]),
495-
(:on_error, [:default, e -> (e.msg == "foobar" ? true : rethrow(e))]),
495+
(:on_error, [:default, e -> (e.msg == "foobar" ? true : rethrow())]),
496496
(:retry_delays, [:default, fill(0.001, 1000)]),
497497
(:retry_check, [:default, (s,e) -> (s,endswith(e.msg,"foobar"))]),
498498
]
@@ -552,9 +552,9 @@ function walk_args(i)
552552

553553
try
554554
results_test(pmap(mapf, data; kwargs...))
555-
catch e
555+
catch
556556
println("pmap executing with args : ", kwargs)
557-
rethrow(e)
557+
rethrow()
558558
end
559559

560560
return
@@ -662,12 +662,12 @@ if Sys.isunix() # aka have ssh
662662
w_in_remote = sort(remotecall_fetch(workers, p))
663663
try
664664
@test intersect(new_pids, w_in_remote) == new_pids
665-
catch e
665+
catch
666666
print("p : $p\n")
667667
print("newpids : $new_pids\n")
668668
print("w_in_remote : $w_in_remote\n")
669669
print("intersect : $(intersect(new_pids, w_in_remote))\n\n\n")
670-
rethrow(e)
670+
rethrow()
671671
end
672672
end
673673

0 commit comments

Comments
 (0)