Search
 
SCRIPT & CODE EXAMPLE
 

RUST

rust error handling

match do_steps() {
    Ok(_) => (),
    _ => alert_user("Failed to perform necessary steps")
}

// Additional function:
fn do_steps() -> Result<(), Error>{
    do_step_1()?;
    do_step_2()?;
    do_step_3()?;
    // etc
    Ok(())
}
Comment

error handling rust

fn main() {
    let c = div(2.0,0.0);
    match c {
        Ok(t)   =>  println!("c = {t}"),
        Err(e)  =>  println!("{e}")
    }
}

fn div(a:f32, b:f32) -> Result<f32, std::string::String> {
    if b==0.0 {
        let e = std::string::String::from("ZeroDevisionError: float division by zero");
        return Err(e)
    }
    return Ok(a/b)
}
Comment

PREVIOUS NEXT
Code Example
Rust :: Ways to make a sum of squares calculation 
Rust :: rust lang enum 
Rust :: armanriazi•rust•borrowchecker•lifetime•static 
Rust :: How to pass a string literal 
Rust :: armanriazi•rust•string 
Rust :: armanriazi•rust•thread•recv•try_recv 
Rust :: get last index of string rust 
Rust :: Read a floating point number from stdin 
Rust :: armanriazi•rust•mem•leak 
Rust :: rust absolute path 
Rust :: armanriazi•rust•trait•bound 
Rust :: bevy disable plugin 
Rust :: how to get public addres from private key solana cli 
Rust :: how to check if a thing is in a vector in rust 
Rust :: armanriazi•rust•unsafe•static 
Lua :: roblox how to make rainbow part 
Lua :: how to remove characters from a string in lua 
Lua :: lua string to number 
Lua :: lua drawinrect 
Lua :: lua metatable assignment 
Lua :: lua event 
Lua :: loop roblox studio 
Lua :: how to access an index of a table lua 
Lua :: roblox touch part kill script 
Lua :: how to make a number adding in roblox studio 
Lua :: exemple boolean and why it is used 
Lua :: Simple Roblox Lua Function 
Matlab :: count even and odd numbers in matlab 
Matlab :: octave a:b:c range 
Basic :: Trollbox 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =