I observe that stack traces in Julia do not necessarily show the type of the exception that is thrown. For example:
julia> throw(DomainError("moo"))
ERROR: DomainError with moo:
...snip...
includes “DomainError” in the stack trace, but
julia> throw(ProcessFailedException(Base.Process(Base.Cmd([""]), Ptr{Cvoid}(C_NULL))))
ERROR: failed process: Process(`''`, ProcessExited(-9223372036854775808)) [-9223372036854775808]
...snip...
… doesn’t include “ProcessFailedException”. The same lack-of-type-showing occurs for ErrorException
and Downloads.RequestError
too. These are just the ones I’ve come across so far, and I’m pretty new to Julia, so I’m sure there are plenty more examples!
I would find it very helpful if the stack trace always explicitly showed the type of the exception that was thrown, rather than it being up to the exception’s implementation of Base.showerror
.
- If one wishes to handle the exception, it is immediately obvious which type of exception one should handle.
- If writing a custom exception, the onus is not on the writer to ensure that the error message makes the type of the exception clear.
There is also precedent for this in other languages, e.g. Python, Java, Kotlin.
At the moment, if wanting to handle an exception of unknown type, one can run some temporary code like:
try
thing_that_throws()
catch e
println(typeof(e))
rethrow()
end
… but this seems like a step that could be avoided.
Do other people feel the same way?
[For context: I’m using Downloads.download
, and wish to not abort execution if a particular file does not exist. I was migrating from the old Base.download
since Julia 1.6 was released yesterday. The old way would throw a ProcessFailedException
, and the new way a Downloads.RequestError
when a URL wasn’t accessible – both exceptions of types that eluded me until I used code like the above!]