TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Real cost of C++ exception vs error-code checking

71 点作者 zeugma大约 14 年前

6 条评论

pilif大约 14 年前
I assume he was proving a point where main() of his full program using error code checking was not in fact checking the return value of foo()<p>Even in simple example code like this you can forget a check. In this case that result would be undefined if any call to devide failed.<p>I'd much rather have my program blow up with a readable stack trace pointing to where it happened than it working with a basically random value and then maybe blowing up somewhere totally unrelated or worse, destroying user data.
评论 #2302173 未加载
McP大约 14 年前
I prefer Raymond Chen's take on exceptions: <a href="http://blogs.msdn.com/b/oldnewthing/archive/2005/01/14/352949.aspx" rel="nofollow">http://blogs.msdn.com/b/oldnewthing/archive/2005/01/14/35294...</a>
评论 #2301933 未加载
评论 #2301908 未加载
评论 #2301896 未加载
Quarrelsome大约 14 年前
Nice article but as far as I'm concerned you don't need to _prove_ this as it is a logical fallacy to start with.<p>If an exception is being thrown then something is wrong, if something isn't wrong then you implemented your exceptions incorrectly as exceptions shouldn't exist in normal program flow.<p>So to recap, you're writing a crap ton of more code just so you can return your error code _slightly_ faster than it would take an exception. You're optimising your failure cases, which (in the _vast_ majority of cases) is UTTERLY ABSURD.
评论 #2302111 未加载
评论 #2302763 未加载
评论 #2302088 未加载
JoeAltmaier大约 14 年前
Perhaps the worst problem with checking-vs-exceptions is, either solution dominates your code structure, obscuring the algorithm logic.<p>The holy grail would be some method of ensuring the code cannot fail e.g. weirdly constrained argument semantics. Thus separating algorithm from constraints instead of shuffling them together on the page like a deck of cards.
评论 #2303578 未加载
评论 #2304360 未加载
AshleysBrain大约 14 年前
Today with terabyte harddrives, gigabytes of RAM and broadband connections, when is the binary size a more important factor than both execution speed and ease of development? Especially when the binary size difference is probably not huge?<p>Shouldn't the advice of this article just be "use exceptions"?
评论 #2301979 未加载
评论 #2301898 未加载
评论 #2302436 未加载
评论 #2302585 未加载
评论 #2302414 未加载
评论 #2302181 未加载
评论 #2301944 未加载
gersh大约 14 年前
A few issues. Does he actually benchmark? Things don't always work in practice the way you would think.<p>If you are going for ultra-high performance, do you even have error-checking? Do you write it in assembler?