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.

Views on Error Handling

96 pointsby dannasalmost 5 years ago

11 comments

enriqutoalmost 5 years ago
The very concept of &quot;error handling&quot; is absurd.<p>There are no errors, just unnecessary abstractions and control flow hacks. You try to open a file; either you can or you cannot, and both possibilities are equally likely and must be handled by normal control flow in your program. Forcing an artificial asymmetry in the treatment of both cases (as championed by the error handling people) adds ugly complexity to any language that tries to do so.
评论 #23885329 未加载
评论 #23888326 未加载
评论 #23885704 未加载
评论 #23892828 未加载
评论 #23885938 未加载
评论 #23885162 未加载
phoe-krkalmost 5 years ago
There seems to be no mention of the Common Lisp condition system, which allows for handling of exceptional situations actually done right. Is this omission purposeful?<p>See <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=23843525" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=23843525</a> for a recent long discussion about my upcoming book on the topic. (Disclosure: this is a shameless plug.)
评论 #23887205 未加载
评论 #23887691 未加载
评论 #23886921 未加载
评论 #23888264 未加载
gumbyalmost 5 years ago
&gt; but without the downsides of the costly C++ memory deallocation on stack unwinding.<p>I.e. I don’t care about restoring the program to a known state when handling an error (memory deallocation is just one case of processing unwind blocks; locks need releasing,my file handles returned to kernel etc). This really only makes sense when your error “handling” is merely printing a user friendly error message and exiting.
评论 #23887845 未加载
评论 #23887784 未加载
platzalmost 5 years ago
&gt; Composing Errors Codes ... Instead of sprinkling if statements, the error handling can be integrated into the type ... The check for errors is only done once.<p>That is only a superficial level of composition, if one can call it that at all, that doesn&#x27;t account for actual composition of errors of different types. The example provided is just encapsulation and therefore orthogonal to the issue of error handling approaches. i.e. in the example, the error handling code is only centralized, not composed.
评论 #23887740 未加载
nemothekidalmost 5 years ago
The only downside of error codes via Sum types (Rust) seems to be, according to the article, is performance. It then claims that Checked Exceptions are the solution (at least according to Joe Duffy).<p>Maybe I&#x27;m naive to how exceptions are actually implemented, but it seems to me that both a checked exception and Sum Type would incur the same overhead, a single branch to make sure things haven&#x27;t exploded.
评论 #23886763 未加载
评论 #23886689 未加载
identity0almost 5 years ago
The obvious solution (in C++) is not to use exceptions at all, but make your own `error` and `expected&lt;T&gt;` class, and just add [[nodiscard]] to them. All the benefits of Go-style errors, you’ll never forget to check the error, and there is very little runtime overhead. If you pass the error as an out parameter then there is zero runtime overhead on success.
评论 #23887815 未加载
评论 #23885642 未加载
ridiculous_fishalmost 5 years ago
&gt; Swift does not AFAICT provide mechanisms for enforcing checks of return types<p>Swift does this by default! You have to annotate (via @discardableResult) those functions which should <i>not</i> warn.<p>But of course try&#x2F;catch is used in Swift more often.
评论 #23887655 未加载
评论 #23887693 未加载
评论 #23888306 未加载
ensiferumalmost 5 years ago
There are 3 separate things that each require their different approach.<p>- errors i.e bugs made by programmer - logical &quot;error&quot; conditions that the program is expected to handle for example network connection failed or user input failed - unexpected error conditions that typically boild down to resource allocation errors, socket could not be allocated or memory allocation failed etc.<p>In my experience all of these are best handled with a different tool.<p>For bugs use an assert that dumps the core and leaves a clear stack trace. For conditions that the program needs to handle use error codes. And finally for the truly unexpected case use exceptions .
评论 #23885053 未加载
评论 #23885390 未加载
gumbyalmost 5 years ago
An important paper on the trade offs: <a href="http:&#x2F;&#x2F;www.open-std.org&#x2F;jtc1&#x2F;sc22&#x2F;wg21&#x2F;docs&#x2F;papers&#x2F;2018&#x2F;p0709r0.pdf" rel="nofollow">http:&#x2F;&#x2F;www.open-std.org&#x2F;jtc1&#x2F;sc22&#x2F;wg21&#x2F;docs&#x2F;papers&#x2F;2018&#x2F;p070...</a>
bestouffalmost 5 years ago
Rust shines when doing error handling. No way to ignore errors, but properly handling them often adds just a single question mark to your code. Everything stays readable and lightweight.<p>Of course the error handling story is still perfectible but so far it&#x27;s already one of the best I know.
评论 #23884963 未加载
评论 #23885328 未加载
hiflyalmost 5 years ago
No discussion is complete without mention of Erlang’s view on this<p><a href="https:&#x2F;&#x2F;erlang.org&#x2F;download&#x2F;armstrong_thesis_2003.pdf" rel="nofollow">https:&#x2F;&#x2F;erlang.org&#x2F;download&#x2F;armstrong_thesis_2003.pdf</a>
评论 #23885822 未加载
评论 #23885782 未加载