Christopher Smith wrote:
If ComplexSqlSocket calles {new SqlSocket()} in its constructor, and
then the constructor throws, neither ~SqlSocket() nor
~ComplexSqlSocket() gets invoked before you get to the
CrashIfSqlSocketStillOpen.
Yes, that would be true, but of course the SqlSocket and
ComplexSqlSocket constructors are responsible for handling that case and
are at liberty to employ "using" or try/catch blocks to do so.
Errr, no. If ComplexSqlSocket creates a SqlSocket, and then Foo's
constructor throws, ComplexSqlSocket isn't part of the using block.
body rather than in the initialization block. What happens if you have a
derived class that successfully invokes the its base class constructor
but later throws an exception in the constructor body?
In C++? It destructs the base class instance. In C#, it leaves it
hanging around for the GC to handle. That's precisely my point. :-)
Hopefully when Java adopts its own version of using, it will learn from
C#'s experiences.
One can hope. It's amazing how much Java has evolved since it actually
started getting competition from C#.
--
Darren New / San Diego, CA, USA (PST)
His kernel fu is strong.
He studied at the Shao Linux Temple.
--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg