Since your function is called validate_data(), I would only throw an exception if there is an internal error inside the function, and use trueor falseto indicate that the function checked the input, but it was either valid( return true) or incorrect ( return false).
This will not stop you from having multiple constructs if() else if() else, but it will make the code cleaner and easier to distinguish if the data was invalid or an internal error occurred.
try {
bool valid = validate_data(foo);
} catch (std::exception &ex) {
}
as you can see, this will make your code longer, IMHO clean.
source
share