Error Handling
Try / Catch
fn load_config(path: String) -> Config ![io] {
try {
let content = fs.read(path);
return Config.parse(content);
} catch (e: IoError) {
print.error("Cannot read config: {{e.message}}");
throw e;
} finally {
print.info("Config loading attempted");
}
}
Result Types
For functions that return errors as values:
enum Result<T, E> {
Ok(T),
Err(E),
}
fn parse_int(s: String) -> Result<Int, String> {
// ...
}
fn main() ![io] {
match parse_int("42") {
Ok(n) => print.info("Parsed: {{n}}"),
Err(msg) => print.error("Failed: {{msg}}"),
}
}
Next Steps
- Concurrency — Routines, channels, and parallelism
- Testing — Writing and running tests