From cc7f9aa1e1e1224877431c5b3ca47e5332286c5f Mon Sep 17 00:00:00 2001 From: Mus M Date: Tue, 22 Aug 2017 17:04:37 -0400 Subject: [PATCH] simplify Amos exception (#46) --- src/bessel.jl | 38 ++++++++++++++++++-------------------- test/runtests.jl | 2 +- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/bessel.jl b/src/bessel.jl index 68246872..343d6f31 100644 --- a/src/bessel.jl +++ b/src/bessel.jl @@ -4,28 +4,26 @@ using Base.Math: nan_dom_err struct AmosException <: Exception 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 + +function Base.showerror(io::IO, ex::AmosException) + print(io, "AmosException with id $(ex.id): ") + if ex.id == 0 + print(io, "normal return, computation complete.") + elseif ex.id == 1 + print(io, "input error.") + elseif ex.id == 2 + print(io, "overflow.") + elseif ex.id == 3 + print(io, "input argument magnitude large, less than half machine accuracy loss by argument reduction.") + elseif ex.id == 4 + print(io, "input argument magnitude too large, complete loss of accuracy by argument reduction.") + elseif ex.id == 5 + print(io, "algorithm termination condition not met.") + else + print(io, "invalid error flag.") end end -Base.showerror(io::IO, err::AmosException) = print(io, "AmosException with id $(err.id): $(err.msg)") ## Airy functions function _airy(z::Complex128, id::Int32, kode::Int32) diff --git a/test/runtests.jl b/test/runtests.jl index a9b62b6c..9fca65cb 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -544,4 +544,4 @@ end @test typeof(SF.zeta(complex(1), 2.0)) == Complex{Float64} end -@test sprint(showerror, SF.AmosException(1)) == "AmosException with id 1: Input error" +@test sprint(showerror, SF.AmosException(1)) == "AmosException with id 1: input error."