Consider this simple example:
function failme() error("failme() failed") end function test() try failme() catch err error("error in test(): $err") end end function main() try test() catch err println("error in main(): $err") quit() end end
main() returns the following (on Julia 0.6.2 on Debian):
error in main(): ErrorException("error in test(): ErrorException(\"failme() failed\")")
Note how the innermost part gets mangled by escaping the quotes (which should not be part of the string) - is this a bug and if so, should i report it somewhere?
A couple of notes/questions:
- Is this a wrong way of using exceptions in Julia, or should it work? In the real code, the reason for catching the exception in the “middle layer” is that I can add more information/context to the error message.
- I tried to replace
error("info")with a custom exception (based on this code), but this gives the same result as long as I include
$errin the message of the exception thrown in
$(sprint(showerror, err))helps, but looks weird
throw()helps as well, but it feels wrong to throw strings … but might be the easiest solution
As usual, I am probably missing something obvious…