Skip to content

Commit dd2cbe0

Browse files
committed
Outline error handling
1 parent 9821912 commit dd2cbe0

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/exception.jl

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ callsym(s::QuoteNode) = s.value
7070
import Base.Meta.isexpr
7171
callsym(ex::Expr) = isexpr(ex,:macrocall,2) ? callsym(ex.args[2]) : isexpr(ex,:ccall) ? callsym(ex.args[1]) : ex
7272

73+
"""
74+
_handle_error(msg)
75+
76+
Throw a PyError if available, otherwise throw ErrorException.
77+
This is a hack to manually do the optimization described in
78+
https://github.com/JuliaLang/julia/issues/29688
79+
"""
80+
@noinline function _handle_error(msg)
81+
pyerr_check(msg)
82+
error(msg, " failed")
83+
end
84+
7385
# Macros for common pyerr_check("Foo", ccall((@pysym :Foo), ...)) pattern.
7486
macro pycheck(ex)
7587
:(pyerr_check($(string(callsym(ex))), $(esc(ex))))
@@ -80,9 +92,7 @@ macro pycheckv(ex, bad)
8092
quote
8193
val = $(esc(ex))
8294
if val == $(esc(bad))
83-
# throw a PyError if available, otherwise throw ErrorException
84-
pyerr_check($(string(callsym(ex))))
85-
error($(string(callsym(ex))), " failed")
95+
_handle_error($(string(callsym(ex))))
8696
end
8797
val
8898
end

0 commit comments

Comments
 (0)