Pattern matching

Errors and optional results that are discussed in Errors and optional results represent two specific types of pattern matching. However, there are many other ways you can use pattern matching in Motoko programs. This section highlights other examples of pattern matching.

  • point: unhandled errors are a special case of non-exhaustive pattern match (for results and option types)

  • point: null-pointer errors are a special case of non-exhaustive pattern match

  • the Motoko type checker statically enforces exhaustive pattern matches for all optional types (and variants); hence, null-pointer errors are ruled out statically, and are impossible dynamically.