I was wondering if it's possible to exit a function early, bypassing the remainder of the code in the body. For example:
public class SOMECLASS {
public SOMECLASS( int i ) {
gotoSwitchCase(i);
additionalTask(); // method body is irrelevant
}
private void gotoSwitchCase(int i) {
switch (i) {
case 0:
/* exit ctor prematurely */
break;
default:
/* set some instance variables, return to ctor */
}
}
}
I know that I can insert if(i==0){return;}
at the very beginning of additionalTask()
to skip that part. However, I'm more interested in whether or not there is a way to exit the constructor (or any function) gracefully without visiting the rest of it's body. Similar to an exception, but not as fatal.