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:
parent
b12b4e4e32
commit
8f99ad2a2a
1 changed files with 10 additions and 0 deletions
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue