A little scenario in C++
class X(
 X()
 { CString x = new CString("dsadsad");
   throw exception.....
}
}

This causes a memory leak, because CString x is never deleted.

.NET has a garbage collector, so this is not an issue in .NET!
According to me: feel free to use exceptions in constructors!
Even more, use exceptions is the only nice way to make clear that
construction was unsuccessful!

Martijn de Haas
<A href="http://www.artifactory.nl";>http://www.artifactory.nl</a>


On Wed, 31 Mar 2004 09:29:57 -0500, Chris Snyder
<[EMAIL PROTECTED]> wrote:

>I have a (hopefully) simple question.
>
>In a nutshell, as a C++ developer, various people hammered into my brain
>that throwing an exception in a constructor (whether intentionally or by
>performing some action which would cause an exception to be thrown) was
>extremely bad. However, my research seems to indicate that .NET handles
>constructors differently, allowing developers to perform actions in a
>constructor that may result in exceptions being thrown, or to <gasp> even
>throw an exception themselves.
>
>Thoughts?
>
>Thanks a lot,
>Chris Snyder
>
>===================================
>This list is hosted by DevelopMentorŪ  http://www.develop.com
>Some .NET courses you may be interested in:
>
>NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles
>http://www.develop.com/courses/gaspdotnetls
>
>View archives and manage your subscription(s) at http://discuss.develop.com
===================================
This list is hosted by DevelopMentorŪ  http://www.develop.com
Some .NET courses you may be interested in:

NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles
http://www.develop.com/courses/gaspdotnetls

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to