chainerror/searchindex.js

1 line
244 KiB
JavaScript
Raw Normal View History

window.search = {"doc_urls":["tutorial1.html#simple-string-errors","tutorial2.html#simple-chained-string-errors","tutorial2.html#what-did-we-do-here","tutorial3.html#mapping-errors","tutorial4.html#saving-coding-chars","tutorial5.html#the-source-of-errors","tutorial6.html#downcast-the-errors","tutorial7.html#the-root-cause-of-all-errors","tutorial8.html#finding-an-error-cause","tutorial9.html#selective-error-handling","tutorial10.html#errorkind-to-the-rescue","tutorial11.html#debug-for-the-errorkind"],"index":{"documentStore":{"docInfo":{"0":{"body":63,"breadcrumbs":3,"title":3},"1":{"body":556,"breadcrumbs":4,"title":4},"10":{"body":603,"breadcrumbs":2,"title":2},"11":{"body":613,"breadcrumbs":2,"title":2},"2":{"body":45,"breadcrumbs":1,"title":1},"3":{"body":581,"breadcrumbs":2,"title":2},"4":{"body":567,"breadcrumbs":3,"title":3},"5":{"body":581,"breadcrumbs":2,"title":2},"6":{"body":564,"breadcrumbs":2,"title":2},"7":{"body":566,"breadcrumbs":3,"title":3},"8":{"body":558,"breadcrumbs":3,"title":3},"9":{"body":563,"breadcrumbs":3,"title":3}},"docs":{"0":{"body":"The most simplest of doing error handling in rust is by returning String as a Box<Error> . As you can see by running the example (the \"Play\" button in upper right of the code block), this only prints out the last Error . If the rust main function returns an Err(), this Err() will be displayed with std::fmt::Debug . use std::error::Error;\nuse std::result::Result; fn do_some_io() -> Result<(), Box<Error>> { Err(\"do_some_io error\")?; Ok(())\n} fn func2() -> Result<(), Box<Error>> { if let Err(_) = do_some_io() { Err(\"func2 error\")?; } Ok(())\n} fn func1() -> Result<(), Box<Error>> { if let Err(_) = func2() { Err(\"func1 error\")?; } Ok(())\n} fn main() -> Result<(), Box<Error>> { func1()\n}","breadcrumbs":"Simple String Errors","id":"0","title":"Simple String Errors"},"1":{"body":"Now with the help of the chainerror crate, we can have a nicer output. Press the play button in the upper right corner and see the nice debug output. use crate::chainerror::*;\nuse std::error::Error;\nuse std::result::Result; fn do_some_io() -> Result<(), Box<Error>> { Err(\"do_some_io error\")?; Ok(())\n} fn func2() -> Result<(), Box<Error>> { if let Err(e) = do_some_io() { Err(cherr!(e, \"func2 error\"))?; } Ok(())\n} fn func1() -> Result<(), Box<Error>> { if let Err(e) = func2() { Err(cherr!(e, \"func1 error\"))?; } Ok(())\n} fn main() -> Result<(), Box<Error>> { func1()\n}\n# #[allow(dead_code)]\n# mod chainerror {\n# use std::error::Error;\n# use std::fmt::{Debug, Display, Formatter, Result};\n# use std::result::Result as StdResult;\n# # pub struct ChainError<T> {\n# #[cfg(not(feature = \"no-fileline\"))]\n# occurrence: Option<(u32, &'static str)>,\n# kind: T,\n# error_cause: Option<Box<dyn Error + 'static>>,\n# }\n# # pub type ChainResult<O, E> = StdResult<O, ChainError<E>>;\n# # impl<T: 'static + Display + Debug> ChainError<T> {\n# #[cfg(not(feature = \"no-fileline\"))]\n# pub fn new(\n# kind: T,\n# error_cause: Option<Box<dyn Error + 'static>>,\n# occurrence: Option<(u32, &'static str)>,\n# ) -> Self {\n# Self {\n# occurrence,\n# kind,\n# error_cause,\n# }\n# }\n# # #[cfg(feature = \"no-fileline\")]\n# pub fn new(\n# kind: T,\n# error_cause: Option<Box<dyn Error + 'static>>,\n# _occurrence: Option<(u32, &'static str)>,\n# ) -> Self {\n# Self { kind, error_cause }\n# }\n# # pub fn root_cause(&self) -> Option<&(dyn Error + 'static)> {\n# let mut cause = self as &(dyn Error + 'static);\n# while let Some(c) = cause.source() {\n# cause = c;\n# }\n# Some(cause)\n# }\n# # pub fn find_cause<U: Error + 'static>(&self) -> Option<&U> {\n# let mut cause = self as &(dyn Error + 'static);\n# loop {\n# if cause.is::<U>() {\n# return cause.downcast_ref::<U>();\n# }\n# # match cause.source() {\n# Some(c) => cause = c,\n# None => return None,\n# }\n# }\n# }\n# # pub fn find_chain_cause<U: Error + 'static>(&self) -> Option<&ChainError<U>> {\n# let mut cause = self as &(dyn Error + 'static);\n# loop {\n# if cause.is::<ChainError<U>>() {\n# return cause.downcast_ref::<ChainError<U>>();\n# }\