When the finally code is executed?
-
I'll try to remember you're an ungrateful little brat. Actually you didn't say half of what I did, although you did say something vaguely similar. (Don't reply just to repeat a claim - readers can just look at the thread and decide for themselves.)
Ungrateful for what? you didn't post anything that was designed to help me. I said that the return is executed before the 'finally code' but the function is not complete (returned) until the finally code is processed.
dojohansen wrote:
Actually you didn't say half of what I did
I was not trying to claim to have said what you did - I said you said what I said. Anyway, my point is I don't appreciate something thinking there correcting me by basically saying the same thing. If I said: "1 + 1 = 2" and then someone said: "No, Actually, one add one equals 2" then that person would be considered some sort of idiot, don't you think?
Life goes very fast. Tomorrow, today is already yesterday.
-
Ungrateful for what? you didn't post anything that was designed to help me. I said that the return is executed before the 'finally code' but the function is not complete (returned) until the finally code is processed.
dojohansen wrote:
Actually you didn't say half of what I did
I was not trying to claim to have said what you did - I said you said what I said. Anyway, my point is I don't appreciate something thinking there correcting me by basically saying the same thing. If I said: "1 + 1 = 2" and then someone said: "No, Actually, one add one equals 2" then that person would be considered some sort of idiot, don't you think?
Life goes very fast. Tomorrow, today is already yesterday.
Just for any who are interested then dojohansen sent me an email with the following content... Hi, I don't want the thread to degenerate into a petty fight between you and me about whether or not we contributed something. But I do want to replay to *you* - hence this private message. musefan wrote:Ungrateful for what? you didn't post anything that was designed to help me. I said that the return is executed before the 'finally code' but the function is not complete (returned) until the finally code is processed. I definitely said something that was meant to help, although it was not meant for you specifically. A reply in a forum is a reply to a message, not to the author of the message - if I wanted to address you I'd send a private message like this one. What you said (as you accurately repeat in the above quote) is not wrong, but nor is it very precise. There's no mention of the crucial fact that the return value is evaluated before the finally executes**[I said that the 'finally block' executes after the return - which to me is the same as saying "the return value is evaluated before the finally executes"]. There is also nothing that can help your reader understand that it would make a difference if the method worked with a reference type rather than a value type[personally I see the OP as simply asking if finally code is executed before or after the return statement. Not "how do I add to a variable before returning the value?"]. So although I feel people ought to be very happy to be corrected, and I try to be so myself when I am, this message was not even an attempt to correct you. I merely tried to clarify further and add some information regarding the subtleties that arise from the fact that the return value is evaluated before the finally block runs and returned afterwards. To this, you gave a reply that was less than useless. Having first misinterpreted my message as a correction you decided to give me a snotty reply accusing me of trying to score brownie points by repeating you[I did not accuse you of 'stealing' my answer]**. Frankly I feel that if you thought that was what I was doing you should be kind enough to the rest of the community to either just forget about it, or alternatively bring it up in a private message. [the impression I got (intended or not) was that you were correcting me and then saying it was the same answer - to me that warrants a telling off] musefan wrote:Anyway, my point is I don't appreciate something thinking there corre
-
Just for any who are interested then dojohansen sent me an email with the following content... Hi, I don't want the thread to degenerate into a petty fight between you and me about whether or not we contributed something. But I do want to replay to *you* - hence this private message. musefan wrote:Ungrateful for what? you didn't post anything that was designed to help me. I said that the return is executed before the 'finally code' but the function is not complete (returned) until the finally code is processed. I definitely said something that was meant to help, although it was not meant for you specifically. A reply in a forum is a reply to a message, not to the author of the message - if I wanted to address you I'd send a private message like this one. What you said (as you accurately repeat in the above quote) is not wrong, but nor is it very precise. There's no mention of the crucial fact that the return value is evaluated before the finally executes**[I said that the 'finally block' executes after the return - which to me is the same as saying "the return value is evaluated before the finally executes"]. There is also nothing that can help your reader understand that it would make a difference if the method worked with a reference type rather than a value type[personally I see the OP as simply asking if finally code is executed before or after the return statement. Not "how do I add to a variable before returning the value?"]. So although I feel people ought to be very happy to be corrected, and I try to be so myself when I am, this message was not even an attempt to correct you. I merely tried to clarify further and add some information regarding the subtleties that arise from the fact that the return value is evaluated before the finally block runs and returned afterwards. To this, you gave a reply that was less than useless. Having first misinterpreted my message as a correction you decided to give me a snotty reply accusing me of trying to score brownie points by repeating you[I did not accuse you of 'stealing' my answer]**. Frankly I feel that if you thought that was what I was doing you should be kind enough to the rest of the community to either just forget about it, or alternatively bring it up in a private message. [the impression I got (intended or not) was that you were correcting me and then saying it was the same answer - to me that warrants a telling off] musefan wrote:Anyway, my point is I don't appreciate something thinking there corre
He's obviously a self riteous idiot who likes the sound of his own voice (or rather the look of his own typing). Ive not even seen the name here before today, but in the last few hours he's answering question after question in the most verbose way possible.. often replying to other satisfactory answers (like yours above) just to add his 2pence worth. Ignore him. You do a great job of answering questions here.
-
He's obviously a self riteous idiot who likes the sound of his own voice (or rather the look of his own typing). Ive not even seen the name here before today, but in the last few hours he's answering question after question in the most verbose way possible.. often replying to other satisfactory answers (like yours above) just to add his 2pence worth. Ignore him. You do a great job of answering questions here.
-
Well that is a dumb answer because it's totally unhelpful! You're right that it won't compile, but surely you can see that the question works by simply declaring i at the method level instead. And there is in fact a subtle effect of the try-finally.
int foo()
{
int i = 1;
try { return i; }
finally { i = 5; }
}This code compiles, but what does foo() return? I think quite a lot of people would expect it to return 5, since the finally block is executed before the method returns. But the return value is *evaluated* before the finally block runs and the method returns 1. Now what would happen if we boxed the int in a class of our own?
class BoxedInt { public int Value; }
BoxedInt bar()
{
BoxedInt i = new BoxedInt() { Value = 1 };
try { return i; }
finally { i.Value = 5; }
}While foo() returns 1, bar() returns a BoxedInt whose Value is 5. That's because BoxedInt is a class and thus a reference type, so it does not matter if the return value is evaluated before or after the finally block executes. Change BoxedInt to a struct, and bar will return a BoxedInt with Value equal to 1 as well. I'd say there's some subtlety here, so calling that a stupid question seems to me rather a stretch.
So... you did try it, but asked the question anyway? :confused:
-
So... you did try it, but asked the question anyway? :confused:
Now that got me nicely confused. You replied to my message so presumably "you" means me. But what "it" and "the question" refers to is less clear. I tried many things including compiling and running the various code snippets I've put up on this thread. I may have asked questions too, but I am not the OP so if you were referring to the original message that might explain the confusion. If you did mean I tried something (and consequently found out what it does) and still asked what it does, let me know what it was and I will attempt to communicate whatever it was I was wondering about more clearly. :)
-
Just for any who are interested then dojohansen sent me an email with the following content... Hi, I don't want the thread to degenerate into a petty fight between you and me about whether or not we contributed something. But I do want to replay to *you* - hence this private message. musefan wrote:Ungrateful for what? you didn't post anything that was designed to help me. I said that the return is executed before the 'finally code' but the function is not complete (returned) until the finally code is processed. I definitely said something that was meant to help, although it was not meant for you specifically. A reply in a forum is a reply to a message, not to the author of the message - if I wanted to address you I'd send a private message like this one. What you said (as you accurately repeat in the above quote) is not wrong, but nor is it very precise. There's no mention of the crucial fact that the return value is evaluated before the finally executes**[I said that the 'finally block' executes after the return - which to me is the same as saying "the return value is evaluated before the finally executes"]. There is also nothing that can help your reader understand that it would make a difference if the method worked with a reference type rather than a value type[personally I see the OP as simply asking if finally code is executed before or after the return statement. Not "how do I add to a variable before returning the value?"]. So although I feel people ought to be very happy to be corrected, and I try to be so myself when I am, this message was not even an attempt to correct you. I merely tried to clarify further and add some information regarding the subtleties that arise from the fact that the return value is evaluated before the finally block runs and returned afterwards. To this, you gave a reply that was less than useless. Having first misinterpreted my message as a correction you decided to give me a snotty reply accusing me of trying to score brownie points by repeating you[I did not accuse you of 'stealing' my answer]**. Frankly I feel that if you thought that was what I was doing you should be kind enough to the rest of the community to either just forget about it, or alternatively bring it up in a private message. [the impression I got (intended or not) was that you were correcting me and then saying it was the same answer - to me that warrants a telling off] musefan wrote:Anyway, my point is I don't appreciate something thinking there corre
I tried to take this off the thread because in my opinion personal differences do not belong to a thread where someone asks about a try-finally block, nor do I think it is the place to discuss forum etiquette if that is what you attempt to make it look like you're doing. Since you insist on polluting with this, I shall offer you one more insult for your fragile ego to consume today: You really are the biggest loser I've yet come across.
-
He's obviously a self riteous idiot who likes the sound of his own voice (or rather the look of his own typing). Ive not even seen the name here before today, but in the last few hours he's answering question after question in the most verbose way possible.. often replying to other satisfactory answers (like yours above) just to add his 2pence worth. Ignore him. You do a great job of answering questions here.
At least I'm a "self-rietous idiot" who can spell reasonably well. I've only posted a little over 200 messages since I became a member of CodeProject in 2006, partly because I often have too much work to do to fool around here, partly because I usually take some time to craft responses the way I think people ought to respond. I don't dictate how much detail should be provided in messages or how much care should go into things like clear explanations, correct English grammar and spelling, or code examples that provide clear illustration. But just like you guys presumably do, I post the sort of messages I think the forums need. And you know what? I've had quite a lot of people who appreciated it. Every one of those is worth about a hundred of those smallminded responses I sometimes get that seem motivated by a need to point out that I am no better than them. If I never said I was better and the only reason people react this way is because I provide a decent answer to a question, that's fine by me. It will be interesting to see if you take your own advice and just ignore me.
-
Just for any who are interested then dojohansen sent me an email with the following content... Hi, I don't want the thread to degenerate into a petty fight between you and me about whether or not we contributed something. But I do want to replay to *you* - hence this private message. musefan wrote:Ungrateful for what? you didn't post anything that was designed to help me. I said that the return is executed before the 'finally code' but the function is not complete (returned) until the finally code is processed. I definitely said something that was meant to help, although it was not meant for you specifically. A reply in a forum is a reply to a message, not to the author of the message - if I wanted to address you I'd send a private message like this one. What you said (as you accurately repeat in the above quote) is not wrong, but nor is it very precise. There's no mention of the crucial fact that the return value is evaluated before the finally executes**[I said that the 'finally block' executes after the return - which to me is the same as saying "the return value is evaluated before the finally executes"]. There is also nothing that can help your reader understand that it would make a difference if the method worked with a reference type rather than a value type[personally I see the OP as simply asking if finally code is executed before or after the return statement. Not "how do I add to a variable before returning the value?"]. So although I feel people ought to be very happy to be corrected, and I try to be so myself when I am, this message was not even an attempt to correct you. I merely tried to clarify further and add some information regarding the subtleties that arise from the fact that the return value is evaluated before the finally block runs and returned afterwards. To this, you gave a reply that was less than useless. Having first misinterpreted my message as a correction you decided to give me a snotty reply accusing me of trying to score brownie points by repeating you[I did not accuse you of 'stealing' my answer]**. Frankly I feel that if you thought that was what I was doing you should be kind enough to the rest of the community to either just forget about it, or alternatively bring it up in a private message. [the impression I got (intended or not) was that you were correcting me and then saying it was the same answer - to me that warrants a telling off] musefan wrote:Anyway, my point is I don't appreciate something thinking there corre
Since you're being such a pain in the back about this, I'll just keep it up.
musefan wrote:
I said that the 'finally block' executes after the return - which to me is the same as saying "the return value is evaluated before the finally executes"
Well at this point I cannot just add to what you're saying, because the finally block of course does NOT execute "after the return" - that would be impossible. No part of a method executes after it has returned, and that certainly includes the finally. And saying that is the same "to you" doesn't make it right. If you say "that's what I *meant* to say" I'll just take your word for it, mainly because I don't really think it matters if it is true or not - my goal in contributing in forums is to put some stuff in here for the community to learn about, not to craft replies for you personally. (However, when you take it totally off the thread topic, I prefer to switch to personal messages unless my opponent is so rude as to force me to publicly defend myself.)
musefan wrote:
I did not accuse you of 'stealing' my answer
Read your own reply that started this whole thing. Unless it was precisely that accusation, what content is there in the message? Are you trying to claim you just wanted me to know that you had already said the same thing I said? If so, why did you want me to have this piece of information?
musefan wrote:
yeah maybe I could have handled it differently but you clearly misunderstood my answer and therefore instead of 'correcting' it then you should say you don't understand
First, I didn't correct you, I merely gave what I see as a better explanation. The closest I got to hinting you might have said something less than accurate was to say it was "a bit more subtle". To my mind, this was a way of acknowledging that my additional comment concerned minute details, but it seems to have upset you instead. Second, who are you to tell me what I should and should not post? I am in fact a big fan of saying "I don't understand", but not when I do.
-
Now that got me nicely confused. You replied to my message so presumably "you" means me. But what "it" and "the question" refers to is less clear. I tried many things including compiling and running the various code snippets I've put up on this thread. I may have asked questions too, but I am not the OP so if you were referring to the original message that might explain the confusion. If you did mean I tried something (and consequently found out what it does) and still asked what it does, let me know what it was and I will attempt to communicate whatever it was I was wondering about more clearly. :)
Whoops, I meant to reply to the OP.