this post was submitted on 08 Jul 2021
5 points (85.7% liked)

Rust Programming

8346 readers
15 users here now

founded 5 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 4 points 3 years ago

This is mostly cosmetic, but I kinda like Result better in the example they gave:

#[throws(i32)]
fn foo(x: bool) -> i32 {
    if x {
        0
    } else {
        throw!(1);
    }
}

fn bar(x: bool) -> Result<i32, i32> {
    if x {
        Ok(0)
    } else {
        Err(1)
    }
}

The rust devs put a lot of thought into errors and compile time error checking, its pry just best to use their paradigms instead of using the throws methodology from java and wherever else that comes from.