By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,569 Members | 1,422 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,569 IT Pros & Developers. It's quick & easy.

Am I right in thinking a return value is carried over into a __finally statement?

P: n/a
I mean, is this correct?

try
{
Screen->Cursor = crHourglass;
Do something bad
return false;
else
return true;
}
__finally
{
Screen->Cursor = crDefault;
// No need for return statement here.
}

The question is, will the return value (true or false) be returned
correctly as shown, in the __finally statement?

THX!

Dean

Jul 23 '05 #1
Share this Question
Share on Google+
18 Replies


P: n/a
de*********@yahoo.com wrote:
I mean, is this correct?

try
{
Screen->Cursor = crHourglass;
Do something bad
return false;
else
return true;
}
__finally
This is not C++. If this is another language, look up the newsgroup
that covers that language. If this is a compiler extension, please
post to the newsgroup dedicated to that compiler.
{
Screen->Cursor = crDefault;
// No need for return statement here.
}

The question is, will the return value (true or false) be returned
correctly as shown, in the __finally statement?


No way to tell based on the C++ language specification because it does
not have the "__finally" thing.

V
Jul 23 '05 #2

P: n/a
de*********@yahoo.com wrote:
I mean, is this correct?


Correct according to what? It is clearly not covered by the C++ as
a user is not allowed to even utter certain names, e.g. those
starting with an underscore followed by an underscore or an
uppercase letter. A particular C++ implementation may, as an
extension, grant the user the right to use some of these names and
to associate whatever it desires with these names.

Thus, you should direct your article to an appropriate environment
specific forum.

The C++ way of doing what you want uses an object whose destructor
does the clean-up. You may want to look for RAII.
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.contendix.com> - Software Development & Consulting

Jul 23 '05 #3

P: n/a
This is with the Borland C++ Builder compiler.

Jul 23 '05 #4

P: n/a
de*********@yahoo.com wrote:
This is with the Borland C++ Builder compiler.


Then you should probably post to 'borland.public.cpp.language'.
Jul 23 '05 #5

P: n/a
Yeah you're right, its a borland keyword extension. I'll repost there.

Thanks

Dean

Jul 23 '05 #6

P: n/a
It only gets 1 hit a month though:(

Jul 23 '05 #7

P: n/a
de*********@yahoo.com wrote:
It only gets 1 hit a month though:(


Well, there are many 'borland.public.cpp.*' newsgroups, perhaps look for
another one, or ask in 'borland.public.cppbuilder.language'...
Jul 23 '05 #8

P: n/a
de*********@yahoo.com wrote:
It only gets 1 hit a month though:(

Check the web newsgroups area at http://www.borland.com.
Also if try/finally are defined inside the body of a function returning
a bool, then you should return a value from finally block too.

--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #9

P: n/a
de*********@yahoo.com wrote:
I mean, is this correct?

try
{
Screen->Cursor = crHourglass;
Do something bad
return false;
else
return true;
}
__finally
{
Screen->Cursor = crDefault;
// No need for return statement here.
}

The question is, will the return value (true or false) be returned
correctly as shown, in the __finally statement?


That's not C++. Assuming you mean catch(xxx), then no, the exception is
thrown before the return statement, so the return is never reached and
it is not used at all.

Hmm, did you have

#define __finally catch(...)

that's non-standard and I wouldn't recommend it.

Jul 23 '05 #10

P: n/a
I think it comes originally from Delphi and Pascal use, you know that
builder from borland can compile pascal and C++. And __finally is VERY
useful in Pascal. You can return a value, and its carries it on for you
even after processing the __finally section. Great stuff!

Jul 23 '05 #11

P: n/a
de*********@yahoo.com wrote:
I think it comes originally from Delphi and Pascal use, you know that
builder from borland can compile pascal and C++. And __finally is VERY
useful in Pascal. You can return a value, and its carries it on for you
even after processing the __finally section. Great stuff!


Java also has a finally construct. IIRC it makes sure that the specific
block is /always/ executed, regardless what happens. Would be nice to
have that in C++ too, for cleanup purposes for example.

--
Matthias Kaeppler
Jul 23 '05 #12

P: n/a
Matthias Kaeppler wrote:
de*********@yahoo.com wrote:
I think it comes originally from Delphi and Pascal use, you know that
builder from borland can compile pascal and C++. And __finally is VERY
useful in Pascal. You can return a value, and its carries it on for you
even after processing the __finally section. Great stuff!


Java also has a finally construct. IIRC it makes sure that the specific
block is /always/ executed, regardless what happens. Would be nice to
have that in C++ too, for cleanup purposes for example.


I think the destructors of local objects exist (and are called) exactly
for that purpose.
Jul 23 '05 #13

P: n/a
Victor Bazarov wrote:
Matthias Kaeppler wrote:
de*********@yahoo.com wrote:
I think it comes originally from Delphi and Pascal use, you know that
builder from borland can compile pascal and C++. And __finally is VERY
useful in Pascal. You can return a value, and its carries it on for you
even after processing the __finally section. Great stuff!


Java also has a finally construct. IIRC it makes sure that the
specific block is /always/ executed, regardless what happens. Would be
nice to have that in C++ too, for cleanup purposes for example.

I think the destructors of local objects exist (and are called) exactly
for that purpose.


Too bad not all objects are local :)

--
Matthias Kaeppler
Jul 23 '05 #14

P: n/a
Matthias Kaeppler wrote:
Victor Bazarov wrote:
Matthias Kaeppler wrote:
de*********@yahoo.com wrote:

I think it comes originally from Delphi and Pascal use, you know that
builder from borland can compile pascal and C++. And __finally is VERY
useful in Pascal. You can return a value, and its carries it on for you
even after processing the __finally section. Great stuff!
Java also has a finally construct. IIRC it makes sure that the
specific block is /always/ executed, regardless what happens. Would
be nice to have that in C++ too, for cleanup purposes for example.


I think the destructors of local objects exist (and are called) exactly
for that purpose.

Too bad not all objects are local :)


You don't need to create all objects local. You just need to create
ONE more local class and an object of it:

void function_that_throws() {
struct call_me_finally_for_all_I_care {
~call_me_finally_for_all_I_care() {
// do your non-local clean-up
}
} janitor;
try { throw 42; }
catch(...) { throw; }
}

V
Jul 23 '05 #15

P: n/a
Matthias Kaeppler wrote:
Java also has a finally construct. IIRC it makes sure that the specific
block is /always/ executed, regardless what happens. Would be nice to
have that in C++ too, for cleanup purposes for example.

In C++ it is not needed since we have RAII, but I guess you will happy
to hear that C++/CLI also provides a finally construct, in addition to RAII.


--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #16

P: n/a
Could someone tell me what IIRC and RAII mean?

Jul 23 '05 #17

P: n/a
<de*********@yahoo.com> wrote...
Could someone tell me what IIRC and RAII mean?


If I Remember Correctly, Resource Acquisition Is Initialisation.
Jul 23 '05 #18

P: n/a
de*********@yahoo.com wrote:
Could someone tell me what IIRC and RAII mean?


IIRC is an Internet acronym and it means If I Recall Correctly. :-)

RAII is a technique supported by C++ and its standard library and means
Resource Acquisition is Initialisation:
http://groups.google.com/groups?hl=e....gr%26rnum%3D1


--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #19

This discussion thread is closed

Replies have been disabled for this discussion.