If we write return statement in finally block will it works
fine or throws any error?

Answer Posted / avinash kumar

We can not write any type of return statement inside the
finally block...The reason behind it,finally is block
should have to execute in any case.Return statment is fine
when no exception is generated or generated exception is
properly catched,in these two cases control can easily go
back to caller of method or a method can able to return a
valid datatype..
But what happen when an exception is
generated and is not caught,in this case also finally block
will exectute.After the execution of finally block the
control should goto the Runtime environment,means control
should should go away from the execution.But keeping the
return statement inside finally block,in this case
execution plan force the runtime environment to give the
control to the caller of the method.
So for this reason we
can not put any type of return statement inside finally
block.Because complier checks all the possiblities....

Is This Answer Correct ?    8 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is entity client data provider? : Entity framework

545


What happens when I install the .net framework 3.0? How can I upgrade if I already have the .net framework 2.0 installed?

529


What is conceptual model? : Entity framework

531


Explain what is the difference between view and partial view?

579


What is the domain object?

543






What is entity sql? : Entity framework

561


Is the following route definition a valid route definition? {controller}{action}/{id}

755


Can we free memory explicitly without waiting for garbage collector to free the memory in .net compact framework?

538


What is tempdata?

616


Explain how you can send the result back in JSON format in MVC?

578


What is object service? : Entity framework

635


What is Differnce between html.action and ajax.action?

567


Explain entity lifecycle? : Entity framework

547


Can we change web.config settings from iis?

557


What are ajax helpers in asp.net mvc?

593