This is indeed the way to do this, thanks!
El domingo, 28 de diciembre de 2014 19:27:45 UTC-6, Tim Holy escribió: > > Use `rethrow(e)` rather than `showerror`. > > But FYI: what's going on behind the scenes is actually quite subtle and > nowhere close to obvious. There's a certain amount of magic that gets > performed to display that long, helpful message: see replutil.jl, and the > `showerror` method for `DomainError`. The long error message is not > generated > at the call-site because doing so (IIRC) would have a deleterious effect > on the > compiler's ability to inline, and consequently be a big hit on > performance. > `rethrow` will include the backtrace from the offending line, allowing the > normal error message to appear. > > --Tim > > On Sunday, December 28, 2014 05:08:50 PM Avik Sengupta wrote: > > 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... > >
