# Try-catch statement really slow even if catch is never executed

**URL:** <https://discourse.julialang.org/t/try-catch-statement-really-slow-even-if-catch-is-never-executed/91744>\
**Category:** Performance\
**Tags:** performance\
**Created:** [December 16, 2022, 3:20pm UTC](https://discourse.julialang.org/t/try-catch-statement-really-slow-even-if-catch-is-never-executed/91744 "2022-12-16T15:20:39Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [December 16, 2022, 3:25pm UTC](https://discourse.julialang.org/t/try-catch-statement-really-slow-even-if-catch-is-never-executed/91744/2 "2022-12-16T15:25:18Z")

</div>

> [@Are exceptions in Julia "Zero Cost"](https://discourse.julialang.org/t/are-exceptions-in-julia-zero-cost/38405/8):
>
> It would be interesting to see what you tried. The test is, of course, not zero-cost: you still have to execute the condition to see if the exception should be triggered. I’m not seeing any difference, although there is some inconsistency in the @btime results: function f(n::Int) x = rand(Int) t = 0 try for i = 1:n i == x && error("bad i value") t += i end catch end return t end function g(n::Int) x = rand(Int) t = 0 f…

I wonder if this is a regression?

---

_[View the full topic](https://discourse.julialang.org/t/try-catch-statement-really-slow-even-if-catch-is-never-executed/91744)._
