mirror of
https://github.com/haraldh/chainerror.git
synced 2025-01-31 00:56:41 +01:00
26 lines
488 B
Rust
26 lines
488 B
Rust
use chainerror::*;
|
|
use std::error::Error;
|
|
use std::result::Result;
|
|
|
|
fn do_some_io() -> Result<(), Box<Error>> {
|
|
Err("do_some_io error")?;
|
|
Ok(())
|
|
}
|
|
|
|
fn func2() -> Result<(), Box<Error>> {
|
|
do_some_io().map_err(|e| cherr!(e, "func2 error"))?;
|
|
Ok(())
|
|
}
|
|
|
|
fn func1() -> Result<(), Box<Error>> {
|
|
func2().map_err(|e| cherr!(e, "func1 error"))?;
|
|
Ok(())
|
|
}
|
|
|
|
fn main() -> Result<(), Box<Error>> {
|
|
if let Err(e) = func1() {
|
|
eprintln!("{:?}", e);
|
|
}
|
|
Ok(())
|
|
}
|