Under heavy development. This site describes the intended 1.0 language. Current features and performance vary. Development status
Sn50SnThe SnAPI programming language
Development · Evolving reference

Result & errors

Failures are ordinary values.

Sn is under heavy development. This reference includes the intended 1.0 design; features may be incomplete in the current compiler. Read the status →

The Result type

pub enum Result<T, E> {
    Ok { Value: T; };
    Err { Error: E; };
}

Result is an ordinary nominal enum with named payloads. Recoverable failure is represented in the result type instead of an exception.

Handle both paths

module example.output;
from std.io import Print, TryPrint;

fn Main() -> i32 {
    switch TryPrint("Hello\n") {
        case .Ok => return 0;
        case .Err { Error = _ } => return 1;
    }
}

This example is adapted from the standard library's documented output workflow. TryPrint reports output failure; Print fatal-traps on failure.

Construction

Use .Ok { Value = Expression } or .Err { Error = Expression } with an appropriate expected Result type. Success and error payload names are exactly Value and Error.

Propagation syntax

Error and optional propagation details are evolving. Follow the explicit switch-based form here and consult the toolchain's version-specific reference rather than assuming another language's operator semantics.

Documentation snapshot: October 24, 2026 About versions ↗
Searching Development · language & standard library