?`kānrān 0001

The Truth — Error Handling

Methods

try / gbiyanju

Okanran.try(callback) ? Result

Execute with error catching.

ayanmo result = Okanran.try(ese() {
    // Risky operation
    ayanmo data = Odi.read("missing.txt");
    pada data;
});

ti (Okanran.is_error(result)) {
    Irosu.fo("Operation failed");
} bib?k? {
    Irosu.fo("Success!");
}

throw / pada / ju

Okanran.throw(message: String)

Throw an error.

ti (x < 0) {
    Okanran.throw("Value must be positive");
}

is_error / ?e_a?i?e

Okanran.is_error(value) ? Bool

Check if value is an error.

ayanmo result = Okanran.try(risky_operation);
ti (Okanran.is_error(result)) {
    Irosu.fo("Error occurred");
}

unwrap / ?ii

Okanran.unwrap(result) ? Any

Unwrap result or throw on error.

ayanmo value = Okanran.unwrap(result);

unwrap_or / ?ii_tabi

Okanran.unwrap_or(result, default) ? Any

Unwrap or return default value.

ayanmo value = Okanran.unwrap_or(result, "default");

Example: Safe File Read

ese safe_read(path) {
    ayanmo result = Okanran.try(ese() {
        pada Odi.read(path);
    });
    
    pada Okanran.unwrap_or(result, "");
}

ayanmo content = safe_read("config.json");
ti (content == "") {
    Irosu.fo("Using default config");
} bib?k? {
    Irosu.fo("Config loaded");
}