views:

17

answers:

1

Basically I have something like this:

public void Form1_btnStart_click()
{
Void1()
NextLine
}

Public void Void1()
{
Void2()
}

I need to get out of Void2 or beyond and go to the "NextLine" spot. Other than putting an if statement after each subroutine to see if a certain value is met and then using "return;", which would cause some problems since this is a large program which means that this change wouldn't necessarily be corrected for every possible button that eventually uses this Void2() subroutine and could even break it under many circumstances. Any ideas?

A: 

Throw a custom exception, and wrap your call to Void1() in a try...catch block to catch it.

TreDubZedd
Wouldn't this still have the problem of if any other subroutine called it causing problems?
Bryan
You mean that, only if it's called from Void1(), you need to break out (and not elsewhere)?. If you're looking for different functionality from a single function, depending on where it's called, you're going to have to think "redesign". Functions aren't meant to know anything about their callers, as a general rule. If you really needed to hack it, you could set a flag before calling Void1(), and only throw the exception if that flag is set. (Clear that flag upon returning from Void1(), of course).
TreDubZedd