Ian Griffiths wrote:

> So if you want to assign a bunch of stuff you would just do this:
>
>   temp1 = orig1.Clone();
>   temp2 = orig2.Clone();
>   temp3 = orig3.Clone();
>
>   // If we were going to have thrown we
>   // would have done by now.
>   dest1 = temp1;
>   dest2 = temp2;
>   dest3 = temp3;
>
>
> If this does throw an exeception, it'll do so before it gets to the
> dest1 = temp1. If it gets that far it's not going to go wrong after
> that point. The assignment >operator here just copies references,
> and I don't think that ever throws.

So what happens if temp1 commands some resources (handles, etc.) and
orig2.Clone() throws?

.NET languages are lousy at resource management and exception safety.
C++ got it right with copy constructors, destructors, and automatic
reference counting.

What I can't understand why reference couting wasn't implemented in CLI
as a standard facility. A [Counted] attribute would do the trick nicely.
(No, it's not at odds with garbage collection. Garbage collection would
still be used to reclaim memory, this would work as a layer over it for
managing resources.)

Dejan
www.jelovic.com

You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced 
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to