In a library I have a function which searches for a key in a database and return a non-const reference to an object. I want to handle the case in which the key is not found,
The answer, as the other respondents, said, should be: throw an exception...
Type & get(const Key & k) { if( !my_db.key_exists(k) ) { std::stringstream error; error << "key " << k << " not found"; throw std::runtime_error(error); } return my_db.at(k); }