Reputation
7,347
Top tag
Next privilege 10,000 Rep.
Access moderator tools
Badges
2 23 39
Newest
 Guru
Impact
~149k people reached

Aug
31
comment Why is there no 'finally' construct in C++?
Let us continue this discussion in chat.
Aug
31
comment Why is there no 'finally' construct in C++?
I understand your point - there are some legitimate issues with destructors that might throw - but those are rare. Saying that RAII + exceptions has unresolved issues or that RAII isn't a general-purpose solution simply doesn't match the experience of most C++ developers.
Aug
31
comment Why is there no 'finally' construct in C++?
But your first example is willing to lose exceptions. If complex_cleanup throws, then the original A/B/... exception is lost. From what I understand, languages like Java and C# work the same way with finally - if finally throws, then the original exception is lost. For better or worse, C++ has decided that it refuses to lose exceptions - it would rather call terminate - and, even if it added finally, finally would probably work the same way, so it wouldn't solve your problem. Like I said, if you're willing to lose exceptions, a nested try/catch block should work.
Aug
31
comment Why is there no 'finally' construct in C++?
In your second example, if complex_cleanup can throw, then you could have a case where two uncaught exceptions are in flight at once, just as you would with RAII / destructors, and C++ refuses to allow this. If you want the original exception to be seen, then complex_cleanup should prevent any exceptions, just as it would with RAII / destructors. If you want complex_cleanup's exception to be seen, then I think you can use nested try/catch blocks - although this is a tangent and hard to fit into a comment, so it's worth a separate question.
Aug
30
awarded  Guru
Aug
19
answered Polymorphic template container: shared_ptr vs reference_wrapper
Aug
16
answered Open Source License that prohibits verbatim resale?
Aug
15
answered Starting a Windows task from Linux, what are my options?
Aug
7
comment Can a pimpl variation be implemented without any performance penalty?
@dcmm88 - Thanks for the info on LTO. It's not something I have a whole lot of experience with.
Aug
7
answered Can a pimpl variation be implemented without any performance penalty?
Jun
30
comment Why is Web SQL database deprecated?
In case anyone wants the full history of Web SQL's deprecation, this blog post has details and links for further readong.
Jun
26
answered Sharing functionality between platforms and languages
Jun
21
reviewed Approve Using a stream manipulator (endl) or a newline escape character (\n)?
Jun
20
awarded  Nice Answer
Jun
20
reviewed Approve Using a stream manipulator (endl) or a newline escape character (\n)?
May
16
awarded  Popular Question
May
6
awarded  Good Answer
May
4
revised Style question: To use overloaded version or not?
added 15 characters in body
May
4
answered Style question: To use overloaded version or not?
May
4
comment What makes a program cross-platform or not?
Surely this overstates the case? I know that more esoteric C++ code may run into various compiler bugs in older or lower-quality compilers, but any reasonably standards-conforming compiler should going to handle things like overloading and name lookup the same. The Standard library provides I/O, and (starting with C++11) threading, and filesystem support is being standardized.