Avik, this works:
julia>
try
sqrt(-1)
catch e
bt = catch_backtrace()
showerror(STDERR, e, bt)
end
DomainError
sqrt will only return a complex result if called with a complex argument.
try sqrt(complex(x))
in sqrt at math.jl:131
Ismael VC
El domingo, 28 de diciembre de 2014 19:08:50 UTC-6, Avik Sengupta escribió:
>
>
> So if I do sqrt(-1), it throws a DomainError, but I get a fairly long
> message explaining what is wrong.
>
> julia> sqrt(-1)
> ERROR: DomainError
> sqrt will only return a complex result if called with a complex argument.
> try sqrt(complex(x))
> in sqrt at math.jl:131
>
> If I put the call to sqrt in a try block, how can I access the detailed
> error message in the catch block? One thing I tried is sprint(showerror,
> e), but that only returns "DomainError()", without any additional details.
> .
>
> julia> try
> sqrt(-1)
> catch e
> return sprint(showerror, e)
> end
> "DomainError()"
>
> I'm probably missing something obvious...
>