Its still got bad idea stamped all over it. The object would not get
constructed, this is almost certainly doc'd somewhere.
The following code outputs the string "null"
using System;
public class MyClass
{
public static void Main()
{
A a = null;
try
{
a = new A();
}
catch(Exception){}
if (a==null)
Console.WriteLine("null");
else
Console.WriteLine("not null");
}
}
class A
{
public A()
{
throw new Exception("");
}
}
> -----Original Message-----
> From: Chris Snyder [mailto:[EMAIL PROTECTED]
> Sent: 31 March 2004 15:30
> To: [EMAIL PROTECTED]
> Subject: [ADVANCED-DOTNET] Exceptions in Constructors
>
> 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(r) 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