473,394 Members | 1,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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

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
18 1722
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
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
This is with the Borland C++ Builder compiler.

Jul 23 '05 #4
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
Yeah you're right, its a borland keyword extension. I'll repost there.

Thanks

Dean

Jul 23 '05 #6
It only gets 1 hit a month though:(

Jul 23 '05 #7
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
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
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
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
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
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
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
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
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
Could someone tell me what IIRC and RAII mean?

Jul 23 '05 #17
<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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Michael Winter | last post by:
The following declaration was posted to a forum: cursor: url('path/some.cur'), hand, pointer, text, default; and I'm having a hard time convincing the poster that it's invalid. First of all,...
4
by: Gene | last post by:
When entering a record in a form, I would like a value in a field of the previous record to be entered automatically into a different field of the current record. Which way should I go? Is it also...
3
by: M Davidson | last post by:
Hello all, Thank you in advance for any guidance. (The standard form/subform won't work because my users will mess up and not enter a value for a category. I don't mean to speak ill of...
15
by: Nerox | last post by:
Hi, If i write: #include <stdio.h> int foo(int); int main(void){ int a = 3; foo(a); }
17
by: orekinbck | last post by:
Hi There Say I want to check if object1.Property1 is equal to a value, but object1 could be null. At the moment I have code like this: if (object1 != null) { if (object1.Property ==...
2
by: garyusenet | last post by:
I could do with something similiar, can you tell me if you think this would work for me, and if there's any advantage in working with controls this way than how I currently am. At the moment...
12
by: Mick_fae_Glesga | last post by:
OK, the solution to this is probably blindingly obvious to everyone, but... surely it can't be right. I am compiling with borland bcc32 free compiler this piece of code is designed to identify...
12
by: gnewsgroup | last post by:
I've read the msdn doc about IEnumerable. It seems to me that IEnumerable objects are essentially wrapped-up arrays. It simply gives us the foreach convenience. Is this correct?
7
by: E11esar | last post by:
Hi there. I have written a C# web service that calls an Oracle stored procedure. The SP is a simple select-max query and the table it is getting the value from has about 2.8 million rows in it. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.