Lets say I have a void method/function to check the arguments of the program:
void check(int argc, String argv){
//some irrelevant code
}
In this function I have some checks to validate the correctness of the arguments. For example if there are too much or if they're not recognized.
Should I just quit the program in this function as in example 1, or should I give it a return value and quit it in main()
?
Example 1
void check(int argc, String argv){
if(argc > 4){
print("Too many arguments!");
exit(-1);
}
//code
}
Example 2
int check(int argc, String argv){
if(argc > 4){
print("Too many arguments!");
return -1;
}
//code
}
int main(int argc, String argv){
if(check(argc, argv) == -1){
return -1;
}
}