panic-calm
Cargo Check, Format, Fix and Test / cargo CI (push) Successful in 2m20s Details

This commit is contained in:
Christoph J. Scherr 2024-01-12 15:39:54 +01:00
parent 1066780cff
commit 23f64e119c
Signed by: cscherrNT
GPG Key ID: 8E2B45BC51A27EA7
4 changed files with 41 additions and 0 deletions

4
Cargo.lock generated
View File

@ -874,6 +874,10 @@ version = "11.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575"
[[package]]
name = "panic-calm"
version = "0.1.0"
[[package]] [[package]]
name = "peg" name = "peg"
version = "0.6.3" version = "0.6.3"

View File

@ -3,6 +3,7 @@ members = [
".", ".",
"members/criterion-demo", "members/criterion-demo",
"members/cucumber-demo", "members/cucumber-demo",
"members/panic-calm",
"members/revsqrt", "members/revsqrt",
"members/serde-json-demo", "members/serde-json-demo",
"members/slog-demo", "members/slog-demo",
@ -14,6 +15,7 @@ default-members = [
"members/serde-json-demo", "members/serde-json-demo",
"members/slog-demo", "members/slog-demo",
"members/cucumber-demo", "members/cucumber-demo",
"members/panic-calm",
] ]
[package] [package]

View File

@ -0,0 +1,8 @@
[package]
name = "panic-calm"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

View File

@ -0,0 +1,27 @@
use std::{io::Write, panic};
fn inner() {
let mut counter = 0u8;
loop {
// will eventually panic when overflowing?
counter += 1;
print!("{counter}\t");
if counter % 8 == 0 { println!() }
if counter == 255 {
// so panic will look fancier :)
println!()
}
}
}
fn main() {
// will not catch all panics, only ones that unwind
let panic = panic::catch_unwind(|| {
inner();
});
if panic.is_err() {
dbg!(&panic);
dbg!(&panic.as_ref().unwrap_err().type_id());
println!("recovered from a panic");
}
else {println!("no panic on the titanic")}
}