Notes on Defective C++

Jim Hewes jimhewes at gmail.com
Mon Dec 8 11:51:30 PST 2008


On that web page he says that "the lack of garbage collection makes C++ 
exceptions ... inherently defective." I'm not sure I agree with that. I 
think the opposite is more true. When you're using garbage collection, you 
can't rely on destructors to release resources (notably non-memory 
resources) when exceptions occur. In C# for example, the solution is 
supposed to be the 'using' statment, but that's only useful in the context 
of a function. It doesn't help you when you want class A to be a member of 
another class B and it's lifetime to be governed by the lifetime of class B.

The argument on that web page is that exceptions are defective because 
writing exception-safe code is hard. Well, to me, writing code that uses 
return value error codes and diligently handles all of them is just as hard 
or harder. Especially when you have many layers. And it's more likely that 
you can miss one and your program will blindly continue to execute as if 
everything's OK.

Jim




More information about the Digitalmars-d mailing list