Skip to content

Commit 8f99ad2

Browse files
author
Kevin Brothaler
committed
Update of the book; Error handling, section on custom error types: we should also show the changes to the cause method.
1 parent b12b4e4 commit 8f99ad2

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/doc/book/error-handling.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2019,6 +2019,16 @@ impl Error for CliError {
20192019
CliError::NotFound => "not found",
20202020
}
20212021
}
2022+
2023+
fn cause(&self) -> Option<&error::Error> {
2024+
match *self {
2025+
CliError::Io(ref err) => Some(err),
2026+
CliError::Parse(ref err) => Some(err),
2027+
// Our custom error doesn't have an underlying cause, but we could
2028+
// modify it so that it does.
2029+
CliError::NotFound() => None,
2030+
}
2031+
}
20222032
}
20232033
```
20242034

0 commit comments

Comments
 (0)