Skip to content

Commit 7f2c436

Browse files
c42ffredrikekre
authored andcommitted
Recommend against using the form rethrow(e) (#33296)
This misrepresents the program state and is largely obsoleted by the catch_stack functionality.
1 parent 30940a7 commit 7f2c436

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

base/error.jl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,18 @@ function error(s::Vararg{Any,N}) where {N}
4343
end
4444

4545
"""
46-
rethrow([e])
47-
48-
Throw an object without changing the current exception backtrace. The default argument is
49-
the current exception (if called within a `catch` block).
46+
rethrow()
47+
48+
Rethrow the current exception from within a `catch` block. The rethrown
49+
exception will continue propagation as if it had not been caught.
50+
51+
!!! note
52+
The alternative form `rethrow(e)` allows you to associate an alternative
53+
exception object `e` with the current backtrace. However this misrepresents
54+
the program state at the time of the error so you're encouraged to instead
55+
throw a new exception using `throw(e)`. In Julia 1.1 and above, using
56+
`throw(e)` will preserve the root cause exception on the stack, as
57+
described in [`catch_stack`](@ref).
5058
"""
5159
rethrow() = ccall(:jl_rethrow, Bottom, ())
5260
rethrow(e) = ccall(:jl_rethrow_other, Bottom, (Any,), e)

0 commit comments

Comments
 (0)