Hello,
How does one handle errors thrown in a Base.show
overwrite so that they’re displayed in the REPL and not like this:
this is generated from a file with
struct Foo
fn::String
end
function Base.show(io::IO, ::MIME"image/png", f::Foo)
isfile(f.fn) || error("File not found")
write(io, read(f.fn))
end
Foo("mario.png") # works as expected
Foo("mario_notfound.png") # leads to the error above, I'd like that error to be in the REPL
Interestingly if I copy paste the exact same code in the REPL itself, the error shows in the REPL (though the plot pane still opens which I’d like to avoid).
So to summarise:
- Is there a proper way to collect & display errors that may arise in the application of a
Base.show
so that they are shown in the REPL and not “on the side” - Is there a way to not trigger the opening of the plot-pane if the
Base.show
fails?
thanks!
PS: if it seems weird to have possible errors in a Base.show and not earlier, the reason is that I’d like Foo
to be a container for information to be passed to an external program which then generates the PNG, I want this to only be triggered when necessary and so not a-priori which is why the run command would happen in the Base.show
. But since it may fail, I’d like to know how to do proper error handling.