How do you "break" out of a function?
c++
Solution
You have two options: `return` something or `throw`.
int getNumber()
{
return 3;
}
int getNumber()
{
throw string("Some Var");
}
If you `throw`, you have to `catch` the type you threw.
int maint(int argc, char ** argc)
{
try
{
getNumber();
}
catch(string std)
{
//Your code will execute here if you throw
}
}
Problem
Given a function that returns a value, is it possible to exit the function given a certain condition without returning anything? If so, how can you accomplish this? Example: ``` int getNumber () { . . . } ``` So say you are in this function. Is there a way to exit it without it doing anything?