mirror of
https://github.com/haraldh/chainerror.git
synced 2025-06-06 16:14:43 +02:00
parent
719e221e4b
commit
5c93f1a5fe
21 changed files with 11008 additions and 793 deletions
|
@ -3,9 +3,9 @@
|
|||
<head>
|
||||
<!-- Book generated using mdBook -->
|
||||
<meta charset="UTF-8">
|
||||
<title>Chapter 1 - chainerror</title>
|
||||
<title>Simple String Errors - chainerror</title>
|
||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
||||
<meta name="description" content="">
|
||||
<meta name="description" content="A tutorial for the chainerror rust crate.">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="theme-color" content="#ffffff" />
|
||||
|
||||
|
@ -75,7 +75,7 @@
|
|||
</script>
|
||||
|
||||
<nav id="sidebar" class="sidebar" aria-label="Table of contents">
|
||||
<ol class="chapter"><li><a href="tutorial1.html" class="active"><strong aria-hidden="true">1.</strong> Chapter 1</a></li><li><a href="tutorial2.html"><strong aria-hidden="true">2.</strong> Chapter 2</a></li><li><a href="tutorial3.html"><strong aria-hidden="true">3.</strong> Chapter 3</a></li><li><a href="tutorial4.html"><strong aria-hidden="true">4.</strong> Chapter 4</a></li><li><a href="tutorial5.html"><strong aria-hidden="true">5.</strong> Chapter 5</a></li><li><a href="tutorial6.html"><strong aria-hidden="true">6.</strong> Chapter 6</a></li><li><a href="tutorial7.html"><strong aria-hidden="true">7.</strong> Chapter 7</a></li><li><a href="tutorial8.html"><strong aria-hidden="true">8.</strong> Chapter 8</a></li><li><a href="tutorial9.html"><strong aria-hidden="true">9.</strong> Chapter 9</a></li><li><a href="tutorial10.html"><strong aria-hidden="true">10.</strong> Chapter 10</a></li><li><a href="tutorial11.html"><strong aria-hidden="true">11.</strong> Chapter 11</a></li></ol>
|
||||
<ol class="chapter"><li class="affix"><a href="index.html">chainerror</a></li><li><a href="tutorial1.html" class="active"><strong aria-hidden="true">1.</strong> Simple String Errors</a></li><li><a href="tutorial2.html"><strong aria-hidden="true">2.</strong> Simple Chained String Errors</a></li><li><a href="tutorial3.html"><strong aria-hidden="true">3.</strong> Mapping Errors</a></li><li><a href="tutorial4.html"><strong aria-hidden="true">4.</strong> Saving coding chars</a></li><li><a href="tutorial5.html"><strong aria-hidden="true">5.</strong> The source() of Errors</a></li><li><a href="tutorial6.html"><strong aria-hidden="true">6.</strong> Downcast the Errors</a></li><li><a href="tutorial7.html"><strong aria-hidden="true">7.</strong> The root cause of all Errors</a></li><li><a href="tutorial8.html"><strong aria-hidden="true">8.</strong> Finding an Error cause</a></li><li><a href="tutorial9.html"><strong aria-hidden="true">9.</strong> Selective Error Handling</a></li><li><a href="tutorial10.html"><strong aria-hidden="true">10.</strong> ErrorKind to the rescue</a></li><li><a href="tutorial11.html"><strong aria-hidden="true">11.</strong> Debug for the ErrorKind</a></li><li class="affix"><a href="end.html">The End</a></li></ol>
|
||||
</nav>
|
||||
|
||||
<div id="page-wrapper" class="page-wrapper">
|
||||
|
@ -141,15 +141,25 @@
|
|||
<div id="content" class="content">
|
||||
<main>
|
||||
<a class="header" href="#simple-string-errors" id="simple-string-errors"><h1>Simple String Errors</h1></a>
|
||||
<p>The most simplest of doing error handling in rust is by returning <code>String</code> as a <code>Box<Error></code>.</p>
|
||||
<p>As you can see by running the example (the "Play" button in upper right of the code block), this only
|
||||
<p>An easy way of doing error handling in rust is by returning <code>String</code> as a <code>Box<std::error::Error></code>.</p>
|
||||
<p>If the rust <code>main</code> function returns an <code>Err()</code>, this <code>Err()</code> will be displayed with <code>std::fmt::Debug</code>.</p>
|
||||
<p>As you can see by running the example (by pressing the "Play" button in upper right of the code block),
|
||||
this only
|
||||
prints out the last <code>Error</code>.</p>
|
||||
<p>If the rust <code>main</code> function returns an Err(), this Err() will be displayed with <code>std::fmt::Debug</code>.</p>
|
||||
<pre><code>Error: StringError("func1 error")
|
||||
</code></pre>
|
||||
<p>The next chapters of this tutorial show how <code>chainerror</code> adds more information
|
||||
and improves inspecting the sources of an error.</p>
|
||||
<p>You can also run the tutorial examples in the checked out
|
||||
<a href="https://github.com/haraldh/chainerror">chainerror git repo</a>.</p>
|
||||
<pre><code>$ cargo run -q --example tutorial1
|
||||
</code></pre>
|
||||
<pre><pre class="playpen"><code class="language-rust">use std::error::Error;
|
||||
use std::io;
|
||||
use std::result::Result;
|
||||
|
||||
fn do_some_io() -> Result<(), Box<Error>> {
|
||||
Err("do_some_io error")?;
|
||||
Err(io::Error::from(io::ErrorKind::NotFound))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -170,6 +180,7 @@ fn func1() -> Result<(), Box<Error>> {
|
|||
fn main() -> Result<(), Box<Error>> {
|
||||
func1()
|
||||
}
|
||||
|
||||
</code></pre></pre>
|
||||
|
||||
</main>
|
||||
|
@ -177,6 +188,10 @@ fn main() -> Result<(), Box<Error>> {
|
|||
<nav class="nav-wrapper" aria-label="Page navigation">
|
||||
<!-- Mobile navigation buttons -->
|
||||
|
||||
<a rel="prev" href="index.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
|
||||
<i class="fa fa-angle-left"></i>
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
<a rel="next" href="tutorial2.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
|
||||
|
@ -191,6 +206,10 @@ fn main() -> Result<(), Box<Error>> {
|
|||
|
||||
<nav class="nav-wide-wrapper" aria-label="Page navigation">
|
||||
|
||||
<a href="index.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
|
||||
<i class="fa fa-angle-left"></i>
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
<a href="tutorial2.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
|
||||
|
@ -206,12 +225,6 @@ fn main() -> Result<(), Box<Error>> {
|
|||
|
||||
|
||||
|
||||
<script src="ace.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="editor.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="mode-rust.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="theme-dawn.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="theme-tomorrow_night.js" type="text/javascript" charset="utf-8"></script>
|
||||
|
||||
|
||||
|
||||
<script src="elasticlunr.min.js" type="text/javascript" charset="utf-8"></script>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue