Error codes

E0335: return inside catch

In a terminal: auk explain E0335 prints this page.

On this page

catch e is an expression: it evaluates e and gives its value as T!, with a panic turned into an Err. Its body runs apart from the enclosing function, so return can't jump out of it. ? and fail inside it end the catch with that error instead.

Wrong#

auk
fn first(xs: [int]): int {
  catch { return xs[0] } else 0
}

Fixed#

auk
fn first(xs: [int]): int {
  catch xs[0] else 0
}

Common causes#

  • An early return written inside a catch { ... } block: let the block's value be the result, then return after the catch.

Stuck on a word? Try the glossary. Got a compiler error? Look up its code. Improve this page