Jim Hewes wrote:
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.

In D, you have scope guards, which accomplish the same thing as using in C#. Except with more granularity.

And what are you going to throw an exception from, besides a function? I think you are talking about situations like this:

class A
{
   private File file;
   this () { file = new File ("somePath"); }
   // some operations with side effects that maybe close the file
}

void foo ()
{
   auto a = new A;
   // I want to make sure A's file is cleaned up...how?
}

Reply via email to