possible to skip code from sub functions?

  • Thread starter Thread starter not_a_commie
  • Start date Start date
N

not_a_commie

Is it (even remotely possible) to do the following:

class jump {
void A { go out of this function then skip to C }
void B { do something bad }
void C { do nothing }
}

main () {
jump = new jump
jump.A
jump.B // this line of code got skipped
jump.C
}

I think I could make it happen using the throw keyword and some tricky
exception handling. Is there any other way?
 
not_a_commie said:
Is it (even remotely possible) to do the following:

class jump {
void A { go out of this function then skip to C }
void B { do something bad }
void C { do nothing }
}

main () {
jump = new jump
jump.A
jump.B // this line of code got skipped
jump.C
}

I think I could make it happen using the throw keyword and some tricky
exception handling. Is there any other way?

It can easily be solved by returning a value from A and use that to
determine if the call to B should be done. That however sounds far too
simple for what it seems that you are trying to ask about.

I think that you have to explain what you want to use it for, if you
want any useful advice.
 
Do this without an exception or a return value on any function:

class Jump {
void A() { if(some good reason) throw new Exception(); }
void B() { DestroyTheEarth(); }
void C() { Disarm() ; }
}

main() {
Jump j = new Jump();
try {
j.A();
j.B();
}
catch () { }
finally {
j.C();
}
}


Basically I'm wondering if I can code my own try/catch/finally
structure. I was picturing passing my own exceptions into the try
function and my own delegates to call on catch/final as well. I could
then have my classes call my own throw function. What I can't figure
out how to do is make it skip code. Can I, from my own code, force an
exit from the current scope? Or make it jump back to the scope level
that my custom Try function was called at?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top