mirror of
https://github.com/haraldh/chainerror.git
synced 2025-01-31 00:56:41 +01:00
851 B
851 B
Finding an Error cause
To distinguish the errors occurring in various places, we can define named string errors with the "new type" pattern.
chainerror::str_context!(Func2Error);
chainerror::str_context!(Func1Error);
Instead of chainerror::Error<String>
we now have struct Func1Error(String)
and chainerror::Error<Func1Error>
.
In the main
function you can see, how we can match the different errors.
Also see:
if let Some(f2err) = f1err.find_chain_cause::<Func2Error>() {
as a shortcut to
if let Some(f2err) = f1err.find_cause::<chainerror::Error<Func2Error>>() {
hiding the chainerror::Error<T>
implementation detail.
{{#include ../examples/tutorial8.rs}}
# #[allow(dead_code)]
# mod chainerror {
{{#rustdoc_include ../src/lib.rs:-1}}
# }