Skip to content

Commit

Permalink
Better AMOS error messages (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
musm authored and ararslan committed Aug 17, 2017
1 parent 89ac601 commit 10368b0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/bessel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,29 @@
using Base.Math: nan_dom_err

struct AmosException <: Exception
info::Int32
id::Int32
msg::String

function AmosException(id::Integer)
msg = if id == 0
"Normal return, computation complete."
elseif id == 1
"Input error"
elseif id == 2
"Overflow"
elseif id == 3
"Input argument magnitude large, less than half machine accuracy loss by argument reduction."
elseif id == 4
"Input argument magnitude too large, complete loss of accuracy by argument reduction."
elseif id == 5
"Algorithm termination condition not met."
else
throw(ArgumentError("invalid AMOS error flag: $id"))
end
new(id,msg)
end
end
Base.showerror(io::IO, err::AmosException) = print(io, "AmosException with id $(err.id): $(err.msg)")

## Airy functions
let
Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -543,3 +543,5 @@ end
@test typeof(SF.zeta(complex(1,1), 2f0)) == Complex{Float64}
@test typeof(SF.zeta(complex(1), 2.0)) == Complex{Float64}
end

@test sprint(showerror, SF.AmosException(1)) == "AmosException with id 1: Input error"

0 comments on commit 10368b0

Please sign in to comment.