The Truth Error Handling
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 an error.
ti (x < 0) {
Okanran.throw("Value must be positive");
}
Check if value is an error.
ayanmo result = Okanran.try(risky_operation);
ti (Okanran.is_error(result)) {
Irosu.fo("Error occurred");
}
Unwrap result or throw on error.
ayanmo value = Okanran.unwrap(result);
Unwrap or return default value.
ayanmo value = Okanran.unwrap_or(result, "default");
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");
}