topxebec
topxebec

Reputation: 1427

Is there a method to make a method return in an inner method?

In object oriented language just like JAVA,how to make a method return by inner method?

For example,in some login scenario,we have to check the validation of input values,we just program like this:

...
if(checkValidate()){
   return;
}
dologin()
...

and the method checkValidate() has a return value of Boolean.

Is there a method to directly jump out the father method of the checkValidate(),like this:

...
checkValidate();
doLogin();
...

Just for curious,any suggestion would be appreciated.

Upvotes: 0

Views: 81

Answers (1)

Juned Ahsan
Juned Ahsan

Reputation: 68715

One way to achieve that is by throwing an exception which your father method does not catch. A custom exception, something like : InvalidLoginException

Upvotes: 6

Related Questions