Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Not returning

Status
Not open for further replies.

stevensteven

Programmer
Jan 5, 2004
108
CA
This is probably a silly question but...

Is there some way to not return to a calling function?

For example:
File A Code (CANNOT BE MODIFIED)
FuncA ()
{
FuncB();
// More Code
// I do not want to execute
}

File B Code (CAN BE MODIFIED)
FuncB
{

return;
}
 
you can throw an exception from inside the FuncB that will stop execution all the way backwards until the first try catch block.

for example (this is only the concept, it's not correct as semantic)

Code:
private void FuncA()
{
    try
    {
         FuncB() // throws an exception so the compiler jumps to the cacth section
    }
    catch
    {
         // executes if FunctB or any code inside try throws an exception
    }
    finally
    {
         // executes regardless of how the execution inside the try block goes
    }
}

private void FuncB()
{
    throw new Exception(); // will perpetuate the exception to function A and execution of function B stops
}

another way is to make FuncB return a value and depending on that, you decide if you want to execute the following code or not (if you don't want to execute any code below you use return)

--------------------------
"two wrongs don't make a right, but three lefts do" - the unknown sage
 
if you just want to skip the codes upon return of FuncB(), do an if against the return value of FuncB() (as suggested). To illustrate,

Code:
bool FuncB()
{
  // Some things to do
  return false;
}


void FuncA()
{
  ...
  if(!FuncB()) return;
  // More code
}

But, since FuncA() can't be modified, you may have to raise an error on FuncB(). But (again), someone has to catch the exception, that someone could be the callee of FuncA().
 
stevensteven,
I really don't see a way to do what you want given the fact that you can't modify FuncA(). The solutions proposed will not work because they either required that FuncA() be modified, or assume that it doesn't have try...catch block.

I originally thought of trying to execute each function in another thread but since FuncA() calls FuncB(), FuncB() will run in the same thread as FuncA(). Thus, I don't think what you're trying to accomplish is possible.

JC

_________________________________________________
To get the best response to a question, read faq222-2244.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top