Update of the book; Error handling, section on custom error types: we should also show the changes to the cause method.

This commit is contained in:
Kevin Brothaler 2016-03-18 11:19:20 -04:00
parent b12b4e4e32
commit 8f99ad2a2a

View file

@ -2019,6 +2019,16 @@ impl Error for CliError {
CliError::NotFound => "not found",
}
}
fn cause(&self) -> Option<&error::Error> {
match *self {
CliError::Io(ref err) => Some(err),
CliError::Parse(ref err) => Some(err),
// Our custom error doesn't have an underlying cause, but we could
// modify it so that it does.
CliError::NotFound() => None,
}
}
}
```