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
What is entity client data provider? : Entity framework
What happens when I install the .net framework 3.0? How can I upgrade if I already have the .net framework 2.0 installed?
What is conceptual model? : Entity framework
Explain what is the difference between view and partial view?
What is the domain object?
What is entity sql? : Entity framework
Is the following route definition a valid route definition? {controller}{action}/{id}
Can we free memory explicitly without waiting for garbage collector to free the memory in .net compact framework?
What is tempdata?
Explain how you can send the result back in JSON format in MVC?
What is object service? : Entity framework
What is Differnce between html.action and ajax.action?
Explain entity lifecycle? : Entity framework
Can we change web.config settings from iis?
What are ajax helpers in asp.net mvc?