# Heuristic for checking if a Method always errors

**URL:** https://discourse.julialang.org/t/heuristic-for-checking-if-a-method-always-errors/115125
**Category:** Internals & Design
**Created:** [June 3, 2024, 3:12pm UTC](https://discourse.julialang.org/t/heuristic-for-checking-if-a-method-always-errors/115125 "2024-06-03T15:12:22Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![mrufsvold](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mrufsvold/32/31600_2.png) [@mrufsvold](https://discourse.julialang.org/u/mrufsvold)
#### Post date: [June 3, 2024, 3:12pm UTC](https://discourse.julialang.org/t/heuristic-for-checking-if-a-method-always-errors/115125/1 "2024-06-03T15:12:22Z")

</div>

@oxinabox mused here that it should be possible to use effect analysis to figure out if a method always, sometimes, or never errors.

> [@\[RFC/WIP\] DuckDispatch.jl](https://discourse.julialang.org/t/rfc-wip-duckdispatch-jl/114930/19):
>
> I feel we should really be able to use effects (and a little compile-time code analysisis) to break methods down into Always throws, vs May throw, vs Never throws Probably even to getting a list of all exception types it might throw – should be a reasonable use of abstract interpetetation. Just having “Always throws” or not is enough to eliminate a ton of the false positives – namely the ones that that come from stub definitions that just throw “NotImplementedException”. And that should just …

I don’t know enough about the internals to dig into that at the moment, but it did lead me to wonder if there was a more basic heuristic I could use to at least tell if a method always errors.

I’m wondering if `code_typed` infers that the return type is `Union{}` does that guarantee that the function will error? Like this:

```julia
julia> err_f() = error("")
err_f (generic function with 1 method)

julia> code_typed(err_f, ()) |> only
CodeInfo(
1 ─ invoke Main.error(""::String)::Union{}
└── unreachable
) => Union{}

```

---

<div class="post-metadata">

### Author: ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)
#### Post date: [June 3, 2024, 6:22pm UTC](https://discourse.julialang.org/t/heuristic-for-checking-if-a-method-always-errors/115125/2 "2024-06-03T18:22:41Z")

</div>

> <https://github.com/aviatesk/JET.jl/issues/309>
>
> \`\`\`jl
> f1(x) = error("hello")
> f2(x) = f1(x)
> @report\_call mode=:sound f2(:a)
> \`…\`\`
> 
> says "may throw" but in fact it will throw. If error is the only possible outcome, I should not try to run the code, especially if it will take a long time to execute. The report could distinguish this case when it is sure of the result.

---

<div class="post-metadata">

### Author: ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)
#### Post date: [June 3, 2024, 9:12pm UTC](https://discourse.julialang.org/t/heuristic-for-checking-if-a-method-always-errors/115125/3 "2024-06-03T21:12:12Z")

</div>

> [@mrufsvold](#):
>
> infers that the return type is `Union{}` does that guarantee that the function will error?

An empty union return type means that the function may not ever return a value, so it either runs infinitely or throws.
