There is no single answer to this question, since it depends on how the program as a whole can work with bad input and whether it can reasonably recover when errors are detected (regardless of whether these errors are reported using return codes or by throwing exceptions) .
Can every function that calls to_int() recover immediately from incorrect input? If not, it is better to allow an exception ... so it unwinds the stack until some caller appears (with a try/catch ) that can actually recover from the error.
What if you have many functions that call to_int() , do you want to check in each? If so, this leads to a lot of code duplication.
What if you have a function that calls to_int() , which can recover immediately due to an error, and some others that cannot?
What if you want to report an error to the caller (for example, to allow something more substantial than writing an error line)?
What is not is_all_digits() function? If this is not the case, what if you implement it in such a way as to skip some errors detected by to_int() ? Then you have the worst of both worlds - performing error checking in an attempt to prevent the generation of exceptions, but then the function throws an exception anyway. For example, there may be some global parameter that forces to_int() to accept only octal digits (in the range of 0 to 7 ), but your is_all_digits() function considers all decimal digits to be valid.
More generally, the real need is to define an error handling strategy that works for your program as a whole. An attempt to solve based on the use of a single function between exceptions or exception exceptions is completely absent.
If your program has an error message using exceptions (for example, with one central try/catch in main() , so all errors propagate to the call stack, so main() implements recovery all over the world), and then throws exceptions. If for every function of your program it makes sense to detect errors and quietly handle them in place, avoid exceptions.
What I'm defending allows the dog (your program) to swing its tail (low-level decisions on how to handle errors). Your question, in fact, asks the question of whether to allow the tail to wallow the dog.