I finally found a systematic way of handling simple errors, with anyhow crate!
Using:
.context(...)?;
.with_context(|| lazyfunction(...))?;
return Err(anyhow!(...));
I finally found a systematic way of handling simple errors, with anyhow crate!
Using:
.context(...)?;
.with_context(|| lazyfunction(...))?;
return Err(anyhow!(...));
You can replace
return Err(anyhow!(...));
with
bail!(...)
I am wondering if I could use the lazyfunction within .with_context() for a simple "in place" error recovery.
For example, when an http connection fails, I just want to sleep for a few seconds and then try again just once more.
This seems much simpler than having to create a special type of error for it, return it, then test for it at a calling function, then call this one again, keeping a count of the tries. Or is my idea "unidiomatic"? Any opinions on this?
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.