Home
8 comments
WalterBrightalmost 4 years ago
Working with and implementing C++ exceptions for 30 years now, including implementing exception handling for Windows, DOS extenders, and Posix (all very different), and then re-implementing them for D, I have sadly come to the conclusion that exceptions are a giant mistake.<p>1. they are very hard to understand all the way down<p>2. they are largely undocumented in how they're implemented<p>3. they are slow when thrown<p>4. they are slow when not thrown<p>5. it is hard to write exception-safe code<p>6. very few understand how to write exception-safe code<p>7. there is no such thing as zero-cost exception handling<p>8. optimizers just give up trying to do flow analysis in try-exception blocks<p>9. consider double-fault exceptions - there's something that shows how rotten it is<p>10. has anyone yet found a legitimate use for throwing an `int`?<p>I have quit using exceptions in my own code, making everything 'nothrow'. I regret propagating exception handling into D. Constructors that may throw are an abomination. Destructors that throw are even worse.
评论 #28164956 未加载
评论 #28166759 未加载
评论 #28165788 未加载
评论 #28164333 未加载
评论 #28165346 未加载
评论 #28166876 未加载
评论 #28164736 未加载
评论 #28164925 未加载
评论 #28167041 未加载
评论 #28166581 未加载
评论 #28166469 未加载
评论 #28235166 未加载
评论 #28179460 未加载
评论 #28165989 未加载
评论 #28168412 未加载
评论 #28166830 未加载
评论 #28165110 未加载
评论 #28167572 未加载
nicolasbrailoalmost 4 years ago
Author here; worth noting this article was written a decade ago, and while the concepts it describes are probably still useful (or so I'm told) the text is starting to show its age. Most notably, the examples are completely broken for x86-64, as I didn't have a 64bit processor when writing this.
cecilpl2almost 4 years ago
> When the personality function doesn't know what to do it will invoke the default exception handler, meaning that in most cases throwing from a nothrow method will end up calling std::terminate.<p>This is an interesting tidbit that cost me a week of debugging recently - a try/catch block at the top of the call stack wasn't catching an exception.<p>We set up an exception handler that calls main in a try/catch block, so that any thrown exceptions can be caught, processed, and dispatched to our crash-logging system.<p>But destructors are marked nothrow by default. So we had a case where an object was destroyed, and about 10 levels down from its destructor some other system threw an exception, intending it to be caught by the top-level catch block.<p>But during stack unwinding we passed through the nothrow destructor and std::terminate got called before unwinding got to the top-level try/catch.
评论 #28166175 未加载
adzmalmost 4 years ago
Implementation in Windows is quite different. Especially x86 vs x86-64 which has much less overhead. Also gets quite complicated with the Windows built-in Structured Exceptions/ asynchronous exceptions which can be translated into c++ exceptions -- and even more complexity due to different compiler options that handle these!
AshamedCaptainalmost 4 years ago
[2013]ish if I remember.<p>Also note the ABI for C++ exceptions followed by G++ et al is actually documented as part of the Itanium C++ ABI :<p><a href="https://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html" rel="nofollow">https://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html</a>
评论 #28162344 未加载
评论 #28166749 未加载
pjmlpalmost 4 years ago
Very interesting read, however it is under the hood on a specific implementation.