Why does try\catch not work in this example?

julia> using PlotlyLight

julia> try
           Plot(y=[NaN,NaN])
       catch e
           @warn "NaN in plot"
       end
Error showing value of type Plot:
ERROR: NaN not allowed to be written in JSON spec
1 Like

Probably because the Plot() call does not throw. The try/catch block returns a Plot, which Julia then tries to show; that is when the exception is thrown.

I don’t know how PlotlyLight works, but it’s possible that trying Plot(y=[NaN,NaN]) |> display will throw.

5 Likes