Skip to content

Instantly share code, notes, and snippets.

@erasin
Created October 20, 2016 13:00
Show Gist options
  • Save erasin/44542df8e3b8faf2d6be3cb1bfafdfe7 to your computer and use it in GitHub Desktop.
Save erasin/44542df8e3b8faf2d6be3cb1bfafdfe7 to your computer and use it in GitHub Desktop.
rust error test
use std::error::Error;
fn main() {
match f1() {
Ok(_) => {}
Err(e) => {
println!("{}", e);
}
}
}
fn f1() -> Result<(), Box<Error>> {
if true {
let msg = "错误信息";
return Err(Box::from(format!("Error: {}", msg)));
}
// try!(f1);
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment