// SPDX-License-Identifier: CC-BY-SA-4.0
// SPDX-FileCopyrightText: 2024-2026 hyperpolymath (Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>)
= Lesson 6: Error Handling

== Result Types

Handle errors explicitly:

[source,affinescript]
----
fn divide(a: Int, b: Int) -> Result[Int, String] {
  return if b == 0 {
    Err("division by zero")
  } else {
    Ok(a / b)
  };
}
----

== Propagating Errors

Use `?` operator to propagate:

[source,affinescript]
----
fn compute() -> Result[Int, String] {
  let x = divide(10, 2)?;
  return Ok(x * 2);
}
----

Next: link:lesson-07-effects.adoc[Lesson 7: Effects]
