Show Julia error backtrace in GAP
This is a counterpart of issue #519, which requested to show GAP error backtrace in Julia. It would be good to show also Julia error backrtace in GAP. For example, pure Julia shows the following.
julia> sqrt(-1)
ERROR: DomainError with -1.0:
sqrt will only return a complex result if called with a complex argument. Try sqrt(Complex(x)).
Stacktrace:
[1] throw_complex_domainerror(::Symbol, ::Float64) at ./math.jl:33
[2] sqrt at ./math.jl:557 [inlined]
[3] sqrt(::Int64) at ./math.jl:583
[4] top-level scope at REPL[24]:1
Julia called from a GAP session shows the following (without the Julia stacktrace information).
gap> JuliaEvalString( "sqrt(-1)" )
> ;
Error, DomainError with -1.0:
sqrt will only return a complex result if called with a complex argument. Try sqrt(Complex(x)).
not in any function at *stdin*:2
type 'quit;' to quit to outer loop
brk>
Double indirection (call Julia from GAP from Julia) in a Julia session shows the following (without the inner Julia stacktrace information).
julia> GAP.evalstr( "JuliaEvalString( \"sqrt(-1)\" )")
ERROR: Error thrown by GAP: Error, DomainError with -1.0:
sqrt will only return a complex result if called with a complex argument. Try sqrt(Complex(x)).
not in any function at stream:1
Stacktrace:
[1] error(::String, ::String) at ./error.jl:42
[2] error_handler() at /export/home/sam/gap/4.0/pkg/GAP.jl/src/GAP.jl:158
[3] evalstr_ex at /export/home/sam/gap/4.0/pkg/GAP.jl/src/ccalls.jl:36 [inlined]
[4] evalstr(::String) at /export/home/sam/gap/4.0/pkg/GAP.jl/src/ccalls.jl:63
[5] top-level scope at REPL[2]:1
In order to show also the stacktrace information, we have to change the function handle_jl_exception in JuliaInterface.c. As far as I understand, also the entries of Base.catch_stack() have to be entered in the calls of showerror, but the documentation of Base.catch_stack (in Julia 1.4) contains a warning that this function is experimental in Julia 1.1. Can we rely on this function?
The documentation for Base.catch_stack references https://github.com/JuliaLang/julia/pull/29901 where it is renamed to current_exceptions, but they actually leave the old name in with a deprecation warning. So I think we should be safe to use it for now; dealing with a renaming is also easy enough.
See also #45