4 ms·
Unlike some languages, function return values aren't special, they're just normal values, so you can handle the error locally like match fwrite("aha", f) {
by dbaupp 12y ago
Unlike some languages, function return values aren't special, they're just normal values, so you can handle the error locally like
match fwrite("aha", f) {
Err(e) => println!("Could not write log to database {}", e),
Ok(_) => { /* no problem */ }
}
- ben0x539 12y agoYeah, but that doesn't extend to match { let f = fopen(); fwrite("aha", f); fclose(f); } { Err(e) => println("either of fopen, fwrite or fclose failed"), _ => () } without something like a try! variant that breaks out of a block instead of returning from a function on error.
- vampirebat 12y agoThis is exactly what the Error / Either monad does.
- ben0x539 12y agoCan't be, it does IO!