mirror of
https://github.com/haraldh/chainerror.git
synced 2025-01-31 00:56:41 +01:00
27 lines
756 B
Markdown
27 lines
756 B
Markdown
# Simple String Errors
|
|
|
|
An easy way of doing error handling in rust is by returning `String` as a `Box<std::error::Error>`.
|
|
|
|
If the rust `main` function returns an `Err()`, this `Err()` will be displayed with `std::fmt::Debug`.
|
|
|
|
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 `Error`.
|
|
|
|
~~~
|
|
Error: "func1 error"
|
|
~~~
|
|
|
|
The next chapters of this tutorial show how `chainerror` adds more information
|
|
and improves inspecting the sources of an error.
|
|
|
|
You can also run the tutorial examples in the checked out
|
|
[chainerror git repo](https://github.com/haraldh/chainerror).
|
|
~~~console
|
|
$ cargo run -q --example tutorial1
|
|
~~~
|
|
|
|
~~~rust
|
|
{{#include ../examples/tutorial1.rs}}
|
|
~~~
|