DEVELOP > c-Plus-Plus > Am I right in thinking a return value is carried over into a __finally statement?
| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"" |
| Date: |
04 Mar 2005 07:20:56 AM |
| Object: |
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
.
|
|
| User: "Victor Bazarov" |
|
| Title: Re: Am I right in thinking a return value is carried over into a__finally statement? |
04 Mar 2005 07:59:43 AM |
|
|
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
.
|
|
|
|
| User: "Calum Grant" |
|
| Title: Re: Am I right in thinking a return value is carried over into a__finally statement? |
04 Mar 2005 02:48:27 PM |
|
|
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.
.
|
|
|
| User: "" |
|
| Title: Re: Am I right in thinking a return value is carried over into a __finally statement? |
04 Mar 2005 02:59:32 PM |
|
|
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!
.
|
|
|
| User: "Matthias Kaeppler" |
|
| Title: Re: Am I right in thinking a return value is carried over into a__finally statement? |
04 Mar 2005 03:51:55 PM |
|
|
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
.
|
|
|
| User: "" |
|
| Title: Re: Am I right in thinking a return value is carried over into a __finally statement? |
05 Mar 2005 06:31:16 PM |
|
|
Could someone tell me what IIRC and RAII mean?
.
|
|
|
| User: "Victor Bazarov" |
|
| Title: Re: Am I right in thinking a return value is carried over into a __finally statement? |
05 Mar 2005 06:53:01 PM |
|
|
<deanbrown3d@yahoo.com> wrote...
Could someone tell me what IIRC and RAII mean?
If I Remember Correctly, Resource Acquisition Is Initialisation.
.
|
|
|
|
| User: "Ioannis Vranos" |
|
| Title: Re: Am I right in thinking a return value is carried over into a__finally statement? |
05 Mar 2005 07:07:18 PM |
|
|
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=el&lr=&selm=cd01kl%241ti6%241%40ulysses.noc.ntua.gr&prev=/groups%3Fq%3D%2522resource%2Bacquisition%2Bis%2522%2Bauthor:vranos%26hl%3Del%26lr%3D%26selm%3Dcd01kl%25241ti6%25241%2540ulysses.noc.ntua.gr%26rnum%3D1
--
Ioannis Vranos
http://www23.brinkster.com/noicys
.
|
|
|
|
|
| User: "Victor Bazarov" |
|
| Title: Re: Am I right in thinking a return value is carried over into a__finally statement? |
04 Mar 2005 03:54:19 PM |
|
|
Matthias Kaeppler wrote:
deanbrown3d@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.
.
|
|
|
|
|
|
|
| User: "Dietmar Kuehl" |
|
| Title: Re: Am I right in thinking a return value is carried over into a __finally statement? |
04 Mar 2005 08:02:07 AM |
|
|
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:dietmar_kuehl@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.contendix.com> - Software Development & Consulting
.
|
|
|
| User: "" |
|
| Title: Re: Am I right in thinking a return value is carried over into a __finally statement? |
04 Mar 2005 08:06:49 AM |
|
|
This is with the Borland C++ Builder compiler.
.
|
|
|
| User: "Victor Bazarov" |
|
| Title: Re: Am I right in thinking a return value is carried over into a__finally statement? |
04 Mar 2005 08:17:14 AM |
|
|
wrote:
This is with the Borland C++ Builder compiler.
Then you should probably post to 'borland.public.cpp.language'.
.
|
|
|
| User: "" |
|
| Title: Re: Am I right in thinking a return value is carried over into a __finally statement? |
04 Mar 2005 08:21:39 AM |
|
|
Yeah you're right, its a borland keyword extension. I'll repost there.
Thanks
Dean
.
|
|
|
| User: "" |
|
| Title: Re: Am I right in thinking a return value is carried over into a __finally statement? |
04 Mar 2005 09:01:28 AM |
|
|
It only gets 1 hit a month though:(
.
|
|
|
| User: "Victor Bazarov" |
|
| Title: Re: Am I right in thinking a return value is carried over into a__finally statement? |
04 Mar 2005 09:12:14 AM |
|
|
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'...
.
|
|
|
|
| User: "Ioannis Vranos" |
|
| Title: Re: Am I right in thinking a return value is carried over into a__finally statement? |
04 Mar 2005 11:55:41 AM |
|
|
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
.
|
|
|
|
|
|
|
|
|

|
Related Articles |
|
|