Can we write return statement in finally block?

 Posted by Rajni.Shekhar on 4/12/2012 | Category: ASP.NET Interview questions | Views: 2727 | Points: 40
Answer:

No, we can not write, compiler will give error, because finally block has to be run in any case whether exception occurrs or not, so can not leave the body of finally block.

try

{
}
catch
{
}
finally
{
return;//compile time error: Control cannot leave the body of a finally clause
}


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response