* makes you be explicit about call sites which throw
* makes it easy to reify fallible computation (so it can be stored in e.g. a Future)
For instance:
fn foo() -> Result<Value, IoError> { let x = a()?; let _ = b(); if someCondition { return Err(IoError::Whatever) } return c(x).unwrap(); }
Value foo() throws IOException { x = a(); try { b(); } catch(Exception e) { /* TODO: ERROR HANDLING? */ } if (someCondition) { throw new IOException(); } try { return c(x); } catch(Exception e) { abort(); } }
// RIP typed errors func foo() -> Value throws { let x = try a() // "rethrow" try? b() if someCondition { throw "Oh No IO!" } return try! c(x) }
(My code does have an error because I forgot to wrap the result in Ok)
* makes you be explicit about call sites which throw
* makes it easy to reify fallible computation (so it can be stored in e.g. a Future)
For instance:
is just This is made especially clear by Swift's model which is pretty much exactly the same as Rust's, but makes it look like exceptions: