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
Explain the advantages of asp.net mvc over asp.net?
What is layout in mvc?
Define the core components of an ASP.NET MVC application?
What is object service? : Entity framework
What is the use of view model in asp.net mvc?
what do you mean by table-per-hierarchy?
Is .net framework backwards compatible?
What is renderbody?
What are Model Binders in ASP.Net MVC?
Can I add asp.net mvc testcases in visual studio express?
What is web api‘s in asp.net mvc 4 ?
explain how you can load related entities in ef (entity framework)?
How do I install .net framework?
which are the key concepts of entity data model?
Give an example for authorization filters in an asp.net mvc application?