Skip to content

Commit 10368b0

Browse files
musmararslan
authored andcommitted
Better AMOS error messages (#45)
1 parent 89ac601 commit 10368b0

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/bessel.jl

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,29 @@
33
using Base.Math: nan_dom_err
44

55
struct AmosException <: Exception
6-
info::Int32
6+
id::Int32
7+
msg::String
8+
9+
function AmosException(id::Integer)
10+
msg = if id == 0
11+
"Normal return, computation complete."
12+
elseif id == 1
13+
"Input error"
14+
elseif id == 2
15+
"Overflow"
16+
elseif id == 3
17+
"Input argument magnitude large, less than half machine accuracy loss by argument reduction."
18+
elseif id == 4
19+
"Input argument magnitude too large, complete loss of accuracy by argument reduction."
20+
elseif id == 5
21+
"Algorithm termination condition not met."
22+
else
23+
throw(ArgumentError("invalid AMOS error flag: $id"))
24+
end
25+
new(id,msg)
26+
end
727
end
28+
Base.showerror(io::IO, err::AmosException) = print(io, "AmosException with id $(err.id): $(err.msg)")
829

930
## Airy functions
1031
let

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,3 +543,5 @@ end
543543
@test typeof(SF.zeta(complex(1,1), 2f0)) == Complex{Float64}
544544
@test typeof(SF.zeta(complex(1), 2.0)) == Complex{Float64}
545545
end
546+
547+
@test sprint(showerror, SF.AmosException(1)) == "AmosException with id 1: Input error"

0 commit comments

Comments
 (0)