Created
March 4, 2021 01:58
-
-
Save cindywu/3d73c52f698292252514c110687427dc to your computer and use it in GitHub Desktop.
error things
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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