Skip to content

Commit

Permalink
GSL error handler also now returns information from
Browse files Browse the repository at this point in the history
GSL.

Occasionally the extra information from GSL is useful but cannot be
mapped precisely to an existing Julia exception without losing the
information.

The current hacky solution is to simply print the GSLError object to
STDERR using warn(show(GSLError)).

Should probably have a better solution in the future.
  • Loading branch information
jiahao committed Feb 4, 2016
1 parent cd7c0a5 commit b62723b
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/ConvertGSL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ type GSLError <: Exception
line :: Cint
end

show(io::IO, E::GSLError) = print(io, string("GSL Error", strerror(E.errno), " -- ", E.reason, " at ", E.file, ":", E.line))
show(io::IO, E::GSLError) = print(io, string("GSL Error: ", strerror(E.errno), " -- ", E.reason, " at ", E.file, ":", E.line))

function custom_error_handler(reason::AbstractString, file::AbstractString, line::Integer, errno::Integer)
if errno == 0; return; end # GSL_SUCCESS

warn(GSLError(errno, reason, file, line))
if errno == 1 # GSL_EDOM: input domain error, e.g sqrt(-1)
throw(DomainError())
elseif errno == 2 || errno == 16
Expand Down

0 comments on commit b62723b

Please sign in to comment.