mirror of
https://github.com/haraldh/chainerror.git
synced 2025-06-07 08:34:41 +02:00
doc update
generated from commit 837c7980e8a5b84be28825303faac0ba28e53446
This commit is contained in:
parent
991a7a0786
commit
188d93a86a
15 changed files with 116 additions and 18 deletions
|
@ -140,7 +140,7 @@
|
|||
|
||||
<div id="content" class="content">
|
||||
<main>
|
||||
<a class="header" href="#simple-chained-string-errors" id="simple-chained-string-errors"><h1>Simple Chained String Errors</h1></a>
|
||||
<a class="header" href="#simple-chained-string-errors" id="simple-chained-string-errors"><h2>Simple Chained String Errors</h2></a>
|
||||
<p>Now with the help of the <code>chainerror</code> crate, we can have a nicer output.</p>
|
||||
<p>Press the play button in the upper right corner and see the nice debug output.</p>
|
||||
<pre><pre class="playpen"><code class="language-rust">use crate::chainerror::*;
|
||||
|
@ -449,6 +449,18 @@ fn main() -> Result<(), Box<Error>> {
|
|||
# }
|
||||
# }
|
||||
</code></pre></pre>
|
||||
<a class="header" href="#what-did-we-do-here" id="what-did-we-do-here"><h3>What did we do here?</h3></a>
|
||||
<pre><code class="language-rust ignore"> if let Err(e) = do_some_io() {
|
||||
Err(cherr!(e, "func2 error"))?;
|
||||
}
|
||||
</code></pre>
|
||||
<p>The macro <code>cherr!(cause, newerror)</code> stores <code>cause</code> as the source/cause of <code>newerror</code> and returns
|
||||
<code>newerror</code>, along with the filename (<code>file!()</code>) and line number (<code>line!()</code>).</p>
|
||||
<p><code>Err(e)?</code> then returns the error <code>e</code> applying <code>e.into()</code>, so that we
|
||||
again have a <code>Err(Box<Error>)</code> as a result.</p>
|
||||
<p>The <code>Debug</code> implementation of <code>ChainError<T></code> (which is returned by <code>cherr!()</code>)
|
||||
prints the <code>Debug</code> of <code>T</code> prefixed with the stored filename and line number.</p>
|
||||
<p><code>ChainError<T></code> is in our case <code>ChainError<String></code>.</p>
|
||||
|
||||
</main>
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue