2 ms·
Either allow you to specify a default value on failure, or take an optional `bool* success = nullptr` parameter to indicate failure. Or in C++17, return `std::
by IshKebab 10y ago
Either allow you to specify a default value on failure, or take an optional `bool* success = nullptr` parameter to indicate failure.
Or in C++17, return `std::optional<int>`.
- Suncho 10y agoThen std::atoi() would be making the assumption that you want to handle the error as soon as the function call returns. Furthermore, if you don't check the "success" flag, then your function would fail silently. The exception ensures that something reasonable happens (program termination) when the client does nothing to handle the error. Exceptions are cleaner.