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..

Showing Answers 1 - 12 of 12 Answers

sainirav

  • Aug 26th, 2011
 

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 don’t 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.

Suresh Jayaraman

  • 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;
}


  Was this answer useful?  Yes

Give your answer:

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

 

Related Answered Questions

 

Related Open Questions