GeekInterview.com
Series: Subject: Topic:
Question: 64 of 67

I have a class with constructor, if i throw an error inside the constructor what will become the object while initializing

Asked by: Interview Candidate | Asked on: Nov 25th, 2006
Showing Answers 1 - 1 of 1 Answers

if you throw an error within the constructor of a class, your code will compile but the object will not be instantiated and will through an error. check this sample code:

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

Program objpr = new Program();

Console.WriteLine(objpr);

}

public Program()

{

System.IO.StreamReader objReader = new System.IO.StreamReader("text.txt");

try

{

Console.WriteLine(objReader.ReadToEnd());

}

catch (System.IO.FileNotFoundException exc)

{

new Exception(exc.Message);

}

finally

{

objReader.Close();

}

}

}

}

  
Login to rate this answer.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.