• Dessalines@lemmy.ml
    link
    fedilink
    arrow-up
    4
    ·
    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.