-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Closed
Labels
error handlingHandling of exceptions by Julia or the userHandling of exceptions by Julia or the user
Description
The code here
Lines 87 to 95 in 0413ef0
| function showerror(io::IO, ex, bt; backtrace=true) | |
| try | |
| with_output_color(get(io, :color, false) ? error_color() : :nothing, io) do io | |
| showerror(io, ex) | |
| end | |
| finally | |
| backtrace && show_backtrace(io, bt) | |
| end | |
| end |
tries its best to ensure that the showerror code an exception implement gets printed in red. This can mess up custom coloring that the exception itself tries to do in showerror. For example, here is some code that defines an exception text using colors:
julia> struct CustomException end
julia> function Base.showerror(io::IO, ce::CustomException)
printstyled(io, "This is in red\n"; color=:light_red)
println(io, "This is in white")
end
Trying with the normal two arg showerror and things look ok. But when the error would actually be shown in REPL, the second line would have "magically" also turned red, ruining the formatting.
If an exception wants to print its text in red, it can just implement that with printstyled.
tkfc42f
Metadata
Metadata
Assignees
Labels
error handlingHandling of exceptions by Julia or the userHandling of exceptions by Julia or the user
