|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2003-11-04 19:56:07
"E. Gladyshev" <egladysh_at_[hidden]> writes:
> Here is another example of an "expert article" on this issue.
> This article *is* on practical (real-world) programming.
>
> http://www.cuj.com/documents/s=8000/cujcexp1812alexandr/
>
> Take a look at the Solution 1: Brute Force
> -------------
> void User::AddFriend(User& newFriend)
> {
> friends_.push_back(&newFriend);
> try
> {
> pDB_->AddFriend(GetName(), newFriend.GetName());
> }
> catch (...)
> {
> friends_.pop_back();
> throw;
> }
> }
> [...]
>
> "you catch the exception (no matter what it is), you undo the
> push_back operation with a call to vector::pop_back, and you nicely
> re-throw the exact same exception."
>
> --------------
>
> No mention about the serious catch(...)
> issues on real systems.
> It is just terrible. Imagine how many people
> are going to read this article and use
> this technique because from the description,
> it might work just fine for them and they
> assume the authors are the experts.
> I am sure the authors are experts but sorry,
> in this case, they just weren't very responsible
> to the readers.
The way you're taking code snippets out-of-context is simply
ridiculous. That whole article is expressly about how using
destructors for cleanup is better than writing catch(...) { ...
throw; } blocks.
If you think the world needs to be made more aware of the problems
with catch(...) on some systems and, those problems aside, how "just
terrible" the code looks to you, please be my guest and write some
articles and books. At the same time, try to do it without assailing
as "irresponsible" the work of those who have come before you and who
have contributed much to peoples' understanding of exception-handling.
Since Andrei and Petru advocate the use of destructors over catch(...)
and since I have written about the problems induced by catch(...) on
some systems, your assertion is pure slander. That is in itself
irresponsible, and when people understand that they may be less
inclined to accept whatever technical arguments you have on their own
merit.
where-do-these-people-come-from?-ly y'rs,
-- Dave Abrahams Boost Consulting www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk