{"doc_urls":["tutorial1.html#simple-string-errors","tutorial2.html#simple-chained-string-errors"],"index":{"documentStore":{"docInfo":{"0":{"body":57,"breadcrumbs":3,"title":3},"1":{"body":556,"breadcrumbs":4,"title":4}},"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, 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#pubfnnew(\n#kind:T,\n#error_cause:Option<Box<dynError+'static>>,\n#_occurrence:Option<(u32,&'staticstr)>,\n#)->Self{\n#Self{kind,error_cause}\n#}\n##pubfnroot_cause(&self)->Option<&(dynError+'static)>{\n#letmutcause=selfas&(dynError+'static);\n#whileletSome(c)=cause.source(){\n#cause=c;\n#}\n#Some(cause)\n#}\n##pubfnfind_cause<U:Error+'static>(&self)->Option<&U>{\n#letmutcause=selfas&(dynError+'static);\n#loop{\n#ifcause.is::<U>(){\n#returncause.downcast_ref::<U>();\n#}\n##matchcause.source(){\n#Some(c)=>cause=c,\n#None=>returnNone,\n#}\n#}\n#}\n##pubfnfind_chain_cause<U:Error+'static>(&self)->Option<&ChainError<U>>{\n#letmutcause=selfas&(dynError+'static);\n#loop{\n#ifcause.is::<ChainError<U>>(){\n#returncause.downcast_ref::<ChainError<U>>();\n#}\n##matchcause.source(){\n#Some(c)=>cause=c,\n#None=>returnNone,\n#}\n#}\n#}\n##pubfnkind<'a>(&'aself)->&'aT{\n#&self.kind\n#}\n#}\n##pubtraitChainErrorDown{\n#fnis_chain<T:'static+Display+Debug>(&self)->bool;\n#fndowncast_chain_ref<T:'static+Display+Debug>(&self)->Option<&ChainError<T>>;\n#fndowncast_chain_mut<T:'static+Display+Debug>(&mutself)->Option<&mutChainError<T>>;\n#}\n##usestd::any::TypeId;\n##impl<U:'static+Display+Debug>ChainErrorDownforChainError<U>{\n#fnis_chain<T:'static+Display+Debug>(&self)->bool{\n#TypeId::of::<T>()==TypeId::of::<U>()\n#}\n##fndowncast_chain_ref<T:'static+Display+Debug>(&self)->Option<&ChainError<T>>{\n#ifself.is_chain::<T>(){\n#unsafe{Some(&*(selfas*constdynErroras*const&ChainError<T>))}\n#}else{\n#None\n#}\n#}\n##fndowncast_