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
How do you assign a value to a complex number 7 how has exception hand changed in .net framework 4.0?
What is the use of view model in asp.net mvc?
What is meant by domain model?
what is conceptual model?
What is meant by tempdata in mvc?
How does the .net framework 3.0 relate to windows vista?
What is session state management?
How to bind table colum with gridview column?
What is Separation of Concerns in ASP.NET ASP.Net MVC?
What are advantages of Dependency Injection (DI) in ASP.Net MVC?
Can you please explain the request flow in ASP.NET MVC framework?
Can you use Razor code in Javascript in ASP.Net MVC?
What are the two ways to add constraints to a route?
Is mvc 4 supporting windows azure sdk (software development kit) ?
Can you explain renderbody and renderpage in asp.net mvc?