GeekInterview.com
Series: Subject: Topic:
Question: 8 of 460

Exception Handling

what is the necessary for "throws" and "throw" in exception handling?? Even Though the exception has been thrown automatically and being handled by try and catch block..
Asked by: Interview Candidate | Asked on: Aug 20th, 2011
Showing Answers 1 - 4 of 4 Answers
sainirav

Answered On : Aug 26th, 2011

View all answers by sainirav

throw is very handy when you want to generate exception through your code. For example if the class is inheriting interface and one of the method you dont want to implement in that case you can put like throw throw new NotImplementedException(); . Additionally for the precautionary measure if you know the range which your method can handle you can raise the exception if the method reaches to the maximum value.

Yes  2 Users have rated as useful.
  
Login to rate this answer.
Vimlesh Kumar

Answered On : Sep 9th, 2011

View all answers by Vimlesh Kumar

throw is used in catch block to throw user define exceptions.

ex: throw ( new Exception(" User is not correct"))

  
Login to rate this answer.
Suresh Jayaraman

Answered On : Sep 23rd, 2011

if we have different layers like Dataaccess layer,Business layer ,Presentation layer.
The error is in DataAccess layer,that error should come to presentation layer and we can show that error in message box.it is possible when using throw keyword in try catch block

Ex:

In DataAccessLayer

public void InsertCustomerDAL()
try
{
}
catch(Exception ex)
{
throw ex;
}

Business Layer

InsertCustomerDAL obj=new InsertCustomerDAL();

public void InsertCustomerBL()
try
{
call DAL method here
}
catch(Exception ex)
{
throw ex;
}

Presentation layer

try
{
call BL Method here
}
Catch(Exception ex)
{
this.lblMessage=ex.Message;
}


  
Login to rate this answer.
Sivavt

Answered On : Mar 29th, 2012

View all answers by Sivavt

no throws in C#.

throw is used to re-throw exceptions

  
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.