"Christopher Wright" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]

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?
}

Yes. Thanks for the example. I do that sort of thing a lot, and it applies to anything with a handle such as mutexes, files, etc. In garbage-collected languages, what am I supposed to do there? It would seem that garbage collection and exceptions don't play nice together. Or am I missing something simple?

Could a garbage-collected language ever figure out how to handle this? When class A goes out of scope, how would it know that the file object is not being referenced elsewhere? I wonder if there's a way that reference counting could be used in these cases.

Jim

Reply via email to