E07370: all paths lead to an Exception

Category: E07xxx Full resolution · Reported in phase: SYMBOL_DEFINITION · Classification: STATEMENT_UNREACHABLE · All error codes

What went wrong

You have code after an unconditional exception throw, which can never be executed (dead code).

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 933 (What happens if I write code after a throw statement i...)

How to fix it

  1. Remove unreachable code after throw
  2. Or restructure to have conditional throw

The [EXAMPLE] section below shows a loop whose body always throws (so it can never go round again), and the loop with the throw made conditional.

Common causes

  • Forgot to remove code after exception
  • Logic error in exception handling

See also

  • E07370: unreachable code after throw (this error)
  • E07380: unreachable return after all paths throw

Examples

Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.

Fails with E07370: all paths lead to an Exception

#!ek9
defines module error.e07370.bad

  defines function

    printAll()
      //The loop body always throws, so the loop can never go round a second time
      for item in ["Alpha", "Beta", "Charlie"]
        throw Exception("This will always fail")

Fixed: Throw only when something is wrong

#!ek9
defines module error.e07370.good

  defines function

    printAll()
      stdout <- Stdout()
      for item in ["Alpha", "Beta", "Charlie"]
        if item == "Beta"
          throw Exception("Only fails for Beta")
        stdout.println(item)

Questions and answers

These Q&A entries show E07370 and its fix: