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

Explain RenderBody and RenderPage in ASP.Net MVC?

589


If we write any code for DataGrid methods, what is the access specifier used for that methods in the code behind file and why?

1968


What are Model Binders in ASP.Net MVC?

685


Explain the methods used to render the views in mvc?

542


What is the use of web api ? Why web api needed, if you have already restful services using wcf ?

541






What is edm designer? : Entity framework

557


When using razor views, do you have to take any special steps to protect your asp.net mvc application from cross site scripting (xss) attacks?

691


Explain covariance and contra-variance in .net framework 4.0. Give an example for each.

567


Can I add asp.net mvc testcases in visual studio express?

590


what is complex type?

589


What are scaffold templates in mvc?

576


Where is tempdata stored?

536


What is MVVM design pattern?

593


Explain ASP.NET MVC Identity and Security?

566


Is .net framework dead?

529