# Catching warning and assign missing values instead?

**URL:** <https://discourse.julialang.org/t/catching-warning-and-assign-missing-values-instead/123252>\
**Category:** General Usage\
**Created:** [November 29, 2024, 2:41pm UTC](https://discourse.julialang.org/t/catching-warning-and-assign-missing-values-instead/123252 "2024-11-29T14:41:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Balinus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/balinus/32/243_2.png) [@Balinus](https://discourse.julialang.org/u/Balinus)\
**Post date:** [November 29, 2024, 2:41pm UTC](https://discourse.julialang.org/t/catching-warning-and-assign-missing-values-instead/123252/1 "2024-11-29T14:41:11Z")

</div>

Hello, I get the following warning for some of my calculations.

```julia
┌ Warning: The maximum likelihood algorithm did not find a solution. Maybe try with different initial values or with another method. The returned values are the initial values.
└ @ Extremes ~/.julia/packages/Extremes/4Tbee/src/parameterestimation/maximumlikelihood.jl:20

```

I’d like to be able to catch this warning and instead of keeping the initial values provided by the library, I would like to assign a `missing`, so that we I continue other calculations, I do not get artifact down the line.

I have found this thread: [Catch warnings - #2 by pjgorski](https://discourse.julialang.org/t/catch-warnings/29603/2) but it seems not very elegant and I am wondering if there is a better solution?

---

<div class="post-metadata">

**Author:** ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)\
**Post date:** [November 30, 2024, 6:23pm UTC](https://discourse.julialang.org/t/catching-warning-and-assign-missing-values-instead/123252/2 "2024-11-30T18:23:05Z")

</div>

That’s not a generic warning from Julia but comes from the package Extremes.jl. In order to learn how to handle this situation, I suggest you read its documentation

> **[Extreme value analysis in Julia · Extremes.jl](https://jojal5.github.io/Extremes.jl/stable/)**
>
> Documentation for Extremes.jl.

If need more help, then you should describe what you are doing in more detail. Like how are you using that package? What functions do you call?

---

<div class="post-metadata">

**Author:** ![Balinus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/balinus/32/243_2.png) [@Balinus](https://discourse.julialang.org/u/Balinus)\
**Post date:** [November 30, 2024, 10:46pm UTC](https://discourse.julialang.org/t/catching-warning-and-assign-missing-values-instead/123252/3 "2024-11-30T22:46:07Z")

</div>

Ok, I’ll take a closer look. I thought that catching warning was more a general approach.

I am mostly trying to fit Generalized Pareto to thousands of timeseries (climate models). Threshold selection is harder for some grid point, hence the warnings for some of those time series. My aim is to use the warning and assign a “missing” instead of the fitted parameters that failed.

Thanks!

---

<div class="post-metadata">

**Author:** ![bertschi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bertschi/32/33462_2.png) [@bertschi](https://discourse.julialang.org/u/bertschi)\
**Post date:** [November 30, 2024, 10:58pm UTC](https://discourse.julialang.org/t/catching-warning-and-assign-missing-values-instead/123252/4 "2024-11-30T22:58:46Z")

</div>

Don’t know the package, but the warning says  
`The returned values are the initial values.`  
Thus, instead of catching the warning, I would just check that condition instead and handle it, e.g., assign `missing`.

---

<div class="post-metadata">

**Author:** ![Sevi](https://avatars.discourse-cdn.com/v4/letter/s/c67d28/32.png) [@Sevi](https://discourse.julialang.org/u/Sevi)\
**Post date:** [December 1, 2024, 12:56pm UTC](https://discourse.julialang.org/t/catching-warning-and-assign-missing-values-instead/123252/5 "2024-12-01T12:56:53Z")

</div>

The initial values might be genuine solutions to the problem (perhaps unlikely, but not impossible – but hard to say without more details).

---

<div class="post-metadata">

**Author:** ![Dan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan/32/42581_2.png) [@Dan](https://discourse.julialang.org/u/Dan)\
**Post date:** [December 1, 2024, 1:16pm UTC](https://discourse.julialang.org/t/catching-warning-and-assign-missing-values-instead/123252/6 "2024-12-01T13:16:17Z")

</div>

Maybe this code snippet will help with getting rid of log message:

```julia
julia> Base.CoreLogging.with_logger(Base.CoreLogging.NullLogger()) do
       @warn "hello"
       end

julia> 

```

But it’s also prudent not to turn off logging and getting into Base.CoreLogging isn’t necessarily an exposed API.
