# Catch warnings

**URL:** <https://discourse.julialang.org/t/catch-warnings/29603>\
**Category:** General Usage\
**Created:** [October 7, 2019, 3:51pm UTC](https://discourse.julialang.org/t/catch-warnings/29603 "2019-10-07T15:51:57Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![pjgorski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pjgorski/32/4802_2.png) [@pjgorski](https://discourse.julialang.org/u/pjgorski)\
**Post date:** [March 19, 2020, 11:17pm UTC](https://discourse.julialang.org/t/catch-warnings/29603/2 "2020-03-19T23:17:33Z")

</div>

It is not a general solution, but in my case a function generating warning did it after handling an error, so running `rethrow()` and checking the error details allowed me to properly handle it.

In my case the warning was related with the following error:  
`ERROR: UndefVarError: SparseArrays not defined`

So the code as follows handled it:

```julia
#first throw any error for the rethrow not to catch the previous considered error
try
        throw("")
    catch error
end
#run code that issues the warning
(...)
#check whether there was any error that issued the warning
try
	rethrow()
catch error
	if isa(error, UndefVarError)
		if error.var == Symbol(SparseArrays)
			throw(error)
		end
	end
end

```

---

_[View the full topic](https://discourse.julialang.org/t/catch-warnings/29603)._
