Skip to content

Instantly share code, notes, and snippets.

@cindywu
Created March 4, 2021 01:58
Show Gist options
  • Save cindywu/3d73c52f698292252514c110687427dc to your computer and use it in GitHub Desktop.
Save cindywu/3d73c52f698292252514c110687427dc to your computer and use it in GitHub Desktop.
error things
use std::fs::File;
use std::io::ErrorKind;
fn main() {
let f = File::open("hello.txt");
let _f = match f {
Ok(file) => file,
Err(error) => match error.kind() {
ErrorKind::NotFound => match File::create("hello.txt") {
Ok (fc) => fc,
Err(e) => panic!("problem creating the file: {:?}", e),
},
other_error => {
panic!("Problem opening the file: {:?}", other_error)
}
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment