TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

More than you've ever wanted to know about errors in Rust (2022)

78 pointsby asymmetricalmost 2 years ago

11 comments

codetrotteralmost 2 years ago
It’s a nice summary about error handling in Rust, but doesn’t present anything new for anyone who has been writing Rust for a while.<p>The title “more than you’ve ever wanted to know about errors in Rust” had me expecting to learn something new.<p>Still a nice intro though, and could for example form part of the documentation for shuttle in the future, to help people who are new to Rust get into using shuttle.
评论 #36828480 未加载
评论 #36827049 未加载
评论 #36827820 未加载
Diggseyalmost 2 years ago
&gt; However in Rust, panics cannot be recovered from, there is no way to incept a panic in the current thread.<p>You definitely can: <a href="https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;panic&#x2F;fn.catch_unwind.html" rel="nofollow noreferrer">https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;panic&#x2F;fn.catch_unwind.html</a>
评论 #36828627 未加载
评论 #36828961 未加载
ezekiel68almost 2 years ago
I was very happy to see a recap of all the basics. Sometimes, with new crates coming and going, I worry&#x2F;imagine I may be falling behind on the latest &quot;rustic&quot; ways to handle certain things like this.
Dowwiealmost 2 years ago
The Error rabbit hole goes far deeper than this. I was hoping to read about downcasting and anti-patterns. What were others looking for?
评论 #36829776 未加载
mmastracalmost 2 years ago
If you&#x27;re writing library code and you are new to rust, just stick with `thiserror` and nest your error types (ie: have lower-level errors wrapped up in higher-level errors using #[from]). It&#x27;s barely more effort than using the Any* error types and the benefits of having concrete errors greatly outweigh the tiny bit of extra effort.
WirelessGigabitalmost 2 years ago
Remember,<p><pre><code> std::result::Result&lt;T, E&gt; </code></pre> does not restrict<p><pre><code> E: std::error:Err </code></pre> Whereas the article doesn&#x27;t say that this is the case, but it mentioned it in a way that confused me: <a href="https:&#x2F;&#x2F;www.shuttle.rs&#x2F;blog&#x2F;2022&#x2F;06&#x2F;30&#x2F;error-handling#:~:text=The%20Error%20trait%20is%20defined%20in%20the%20standard%20library.%20It%20basically%20represents%20the%20expectations%20of%20error%20values%20%2D%20values%20of%20type%20E%20in%20Result%3CT%2CE%3E">https:&#x2F;&#x2F;www.shuttle.rs&#x2F;blog&#x2F;2022&#x2F;06&#x2F;30&#x2F;error-handling#:~:tex...</a>.
评论 #36832515 未加载
troupoalmost 2 years ago
I find the concept of unrecoverable panics extremely weird. Crashing your entire program just because something unexpected happened? Erlang would lime a word with you :)
评论 #36828097 未加载
评论 #36835023 未加载
评论 #36828447 未加载
评论 #36828152 未加载
Pesthufalmost 2 years ago
Anyhow and Eyre seem cool, but completely losing all information about what types of Errors the function returns in favor if what is essentially a trait object of std::error::Error seems... questionable to me. I value type safety a lot.
评论 #36831656 未加载
评论 #36832280 未加载
jmakovalmost 2 years ago
No mention of error-stack?
milliamsalmost 2 years ago
*[2022]
mike_hockalmost 2 years ago
TL;DR: It&#x27;s Java&#x27;s explicit throw declarations with extra steps, and syntactic sugar to make the totally-not-exceptions work kinda like exceptions.
评论 #36828656 未加载