Re: Is it possible to end the outermost function from an inner function?
- From: "C. (http://symcbean.blogspot.com/)" <colin.mckinnon@xxxxxxxxx>
- Date: Tue, 30 Sep 2008 05:22:09 -0700 (PDT)
On 30 Sep, 12:21, Kristaps Kūlis <Kristaps.Ku...@xxxxxxxxx> wrote:
On Sep 30, 12:41 pm, Erwin Moller
<Since_humans_read_this_I_am_spammed_too_m...@xxxxxxxxxxxxxxxx> wrote:
-Lost schreef:
Is it possible to end the outermost function from an inner
function?
I've been tasked with implementing a feature check in some existing
code and I wondered if this could be done:
function HorribleCode()
{
TypeCheck(); // if GoodCode_Data is returned, "end" HorribleCode
()
return HorribleCode_Data;
}
function TypeCheck()
{
if (HorribleCode_Data == 'bad')
{
return GoodCode_Data;
}
}
Is this possible without implementing an if-else within
HorribleCode()?
For the, "Why would you want to do this?" crowd, I don't per se,
I'm just curious if it can be done and if so, how?
Thanks for your help!
Hi,
Maybe have a look at try/catch.
Make sure an exception/error occurs when the check fails.
Maybe throw it yourself:
throw new Exception("Horriblecode found a problem");
When you don't catch the exception, all was fine.
Regards,
Erwin Moller
--
============================
Erwin Moller
Now dropping all postings from googlegroups.
Why?http://improve-usenet.org/
============================
exceptions are costly - you should not use them for something like
invalid user input, but just in cases something really went wrong, for
example, when database connection fails.
Certainly, the right way to do it is by returning an appropriate value
(or returning and setting and setting a pass-by-reference parameter).
You can have multiple return statements in a function.
C.
.
- Follow-Ups:
- References:
- Is it possible to end the outermost function from an inner function?
- From: -Lost
- Re: Is it possible to end the outermost function from an inner function?
- From: Erwin Moller
- Re: Is it possible to end the outermost function from an inner function?
- From: Kristaps Kūlis
- Is it possible to end the outermost function from an inner function?
- Prev by Date: Re: html forms and spam-bots
- Next by Date: Re: Flock and file deletion
- Previous by thread: Re: Is it possible to end the outermost function from an inner function?
- Next by thread: Re: Is it possible to end the outermost function from an inner function?
- Index(es):