Is it possible/advisable to have multiline error message?

throw shows a multiline (has \n characters) string as a single line. Example:

julia> throw("a\n b")
ERROR: "a\n b"
Stacktrace:
  [1] top-level scope
  @ REPL[3]:1

Is it possible to have a multiline error message? Is there some reason why this would not be advisable?

Thanks for all the help.

Someone else will have to elaborate on the philosophical use of throw on non-Exception types. Maybe it has to do with not artificially constraining what can be used with try/catch? In any case, it seems that “values” like String aren’t usually meant to be thrown.

In the meantime, consider throw(ErrorException(...)) or equivalently error(...).

julia> error("hi\nthere")
ERROR: hi
there
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] top-level scope
   @ REPL[3]:1
3 Likes