rust-ape-example/src/bin/std_panic.rs
2022-09-07 10:49:49 +05:30

31 lines
560 B
Rust

// ./src/std/panic.md
// Re-implementation of integer division (/)
fn division(dividend: i32, divisor: i32) -> i32 {
if divisor == 0 {
// Division by zero triggers a panic
panic!("division by zero");
} else {
dividend / divisor
}
}
// The `main` task
fn part0() {
// Heap allocated integer
let _x = Box::new(0i32);
// This operation will trigger a task failure
division(3, 0);
println!("This point won't be reached!");
// `_x` should get destroyed at this point
}
pub fn main() {
part0();
}