Return statement in try block
-
Refering below, will the code in
finally
block be executed even if areturn
is called in the try block?void Somefunc()
{
try {
.
.
return;
}
catch(Exception) {
.
.
}
finally {
.
SomeCode();
}
}Weiye Chen Give me the Death Note, and I'll cleanse the world...
-
Refering below, will the code in
finally
block be executed even if areturn
is called in the try block?void Somefunc()
{
try {
.
.
return;
}
catch(Exception) {
.
.
}
finally {
.
SomeCode();
}
}Weiye Chen Give me the Death Note, and I'll cleanse the world...
hey!! ru testing us ;-) Regards, Bhupi Bhai.
-
hey!! ru testing us ;-) Regards, Bhupi Bhai.
Bhupi Bhai wrote:
ru testing us
:doh: I dont think i would be so free to do such things. Anyway i was trying to confirm if
finally
would be called, but i seem to forgot that i could easiy test it out. :doh: Regardless i saw a link[^] about this. Just for anyone who is interested.Weiye Chen Give me the Death Note, and I'll cleanse the world...
-
hey!! ru testing us ;-) Regards, Bhupi Bhai.
hahhahaa :):) :laugh: :laugh: nice one but you should answer him cz maybe he is knew on C#. The answer is that the finally clause is executed in all the senarios good luck
-
Refering below, will the code in
finally
block be executed even if areturn
is called in the try block?void Somefunc()
{
try {
.
.
return;
}
catch(Exception) {
.
.
}
finally {
.
SomeCode();
}
}Weiye Chen Give me the Death Note, and I'll cleanse the world...
-
Refering below, will the code in
finally
block be executed even if areturn
is called in the try block?void Somefunc()
{
try {
.
.
return;
}
catch(Exception) {
.
.
}
finally {
.
SomeCode();
}
}Weiye Chen Give me the Death Note, and I'll cleanse the world...
It is. The purpose of a finally block is to guarantee that a piece of code will be run, regardless of what else happens in the try catch block. This gives you the ability to guarantee that cleanup code will be carried out.
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.