Skip to content

Commit 708e181

Browse files
Merge pull request #1837 from JuliaSymbolics/as/better-error-type
refactor: throw a better error for unimplemented functions in `codegen_function`
2 parents a1996cd + 9286d09 commit 708e181

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

src/codegen_fn.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1+
struct FunctionUnimplementedError <: Exception
2+
type::String
3+
end
4+
5+
function Base.showerror(io::IO, err::FunctionUnimplementedError)
6+
print(io, "The $(err.type) version for this function is invalid")
7+
end
8+
19
function get_unimplemented_fn(nargs, type)
210
expr = :(function unimplemented()
3-
error("The $($type) version for this function is invalid")
11+
throw($FunctionUnimplementedError($type))
412
end)
513

614
for i in 1:nargs

test/codegen_function.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ end
6868
out_2 = similar(out_1)
6969
h_ip!(out_1, inputs...)
7070
h_julia!(out_2, inputs...)
71-
@test_throws ErrorException h3_oop(inputs...)
71+
@test_throws Symbolics.FunctionUnimplementedError h3_oop(inputs...)
7272
@test out_1 == out_2
7373
h3_ip(out_1, inputs...)
7474
@test out_1 == out_2
75-
@test_throws ErrorException h4_ip(out_1, inputs...)
75+
@test_throws Symbolics.FunctionUnimplementedError h4_ip(out_1, inputs...)
7676
@test h4_oop(inputs...) == h_julia(inputs...)
7777
out_1 = similar(h, Int)
7878
fill!(out_1, 10)

0 commit comments

Comments
 (0)