panic-calm
Cargo Check, Format, Fix and Test / cargo CI (push) Successful in 2m20s
Details
Cargo Check, Format, Fix and Test / cargo CI (push) Successful in 2m20s
Details
This commit is contained in:
parent
1066780cff
commit
23f64e119c
|
@ -874,6 +874,10 @@ version = "11.1.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575"
|
||||
|
||||
[[package]]
|
||||
name = "panic-calm"
|
||||
version = "0.1.0"
|
||||
|
||||
[[package]]
|
||||
name = "peg"
|
||||
version = "0.6.3"
|
||||
|
|
|
@ -3,6 +3,7 @@ members = [
|
|||
".",
|
||||
"members/criterion-demo",
|
||||
"members/cucumber-demo",
|
||||
"members/panic-calm",
|
||||
"members/revsqrt",
|
||||
"members/serde-json-demo",
|
||||
"members/slog-demo",
|
||||
|
@ -14,6 +15,7 @@ default-members = [
|
|||
"members/serde-json-demo",
|
||||
"members/slog-demo",
|
||||
"members/cucumber-demo",
|
||||
"members/panic-calm",
|
||||
]
|
||||
|
||||
[package]
|
||||
|
|
|
@ -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]
|
|
@ -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")}
|
||||
}
|
Loading…
Reference in New Issue