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 :: rust javascript 
Rust :: calculator in rust 
Rust :: rust vec to array 
Rust :: ndarray rust 
Rust :: rust round 2 decimal places 
Rust :: find smallest number in vec rust 
Rust :: armanriazi•rust•smartpointer•box•cons 
Rust :: Project Euler #1 Multiples of 3 or 5 
Rust :: rust vector insert 
Rust :: armanriazi•rust•thread•spawin•move•capture 
Rust :: armanriazi•rust•unsafe•extern 
Rust :: hwllo world in rust 
Rust :: slice indices are of type usize rust 
Rust :: armanriazi•rust•error•[E0782]: trait objects must include the `dyn` keyword 
Rust :: rust print i8 
Rust :: rustdoc 
Rust :: execution duration 
Rust :: rustlang get substring 
Lua :: roblox get player from character 
Lua :: luau make kill brick 
Lua :: roblox tween part 
Lua :: roblox studio part color randomiser 
Lua :: lua add 1 to a variable 
Lua :: lua object 
Lua :: lua calculator 
Lua :: FiveM Lua How to create table of all online player id 
Lua :: random number lua 
Lua :: Lua dynamic variable name 
Matlab :: matlab how to set figure size so you can see plot 
Matlab :: how to get the highest power of polynomial matlab 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =