# Why does try\\catch not work in this example?

**URL:** <https://discourse.julialang.org/t/why-does-try-catch-not-work-in-this-example/104751>\
**Category:** General Usage\
**Created:** [October 9, 2023, 1:09pm UTC](https://discourse.julialang.org/t/why-does-try-catch-not-work-in-this-example/104751 "2023-10-09T13:09:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ovt](https://avatars.discourse-cdn.com/v4/letter/o/87869e/32.png) [@ovt](https://discourse.julialang.org/u/ovt)\
**Post date:** [October 9, 2023, 1:09pm UTC](https://discourse.julialang.org/t/why-does-try-catch-not-work-in-this-example/104751/1 "2023-10-09T13:09:24Z")

</div>

```julia
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

```

---

<div class="post-metadata">

**Author:** ![mbaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbaz/32/17295_2.png) [@mbaz](https://discourse.julialang.org/u/mbaz)\
**Post date:** [October 9, 2023, 1:17pm UTC](https://discourse.julialang.org/t/why-does-try-catch-not-work-in-this-example/104751/2 "2023-10-09T13:17:29Z")

</div>

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 `try`ing `Plot(y=[NaN,NaN]) |> display` will throw.
