No return before else
Make function static
Throw system_error to preserve the error code