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,
Exceptions
This is a common situation in many programs. To overcome this, Exceptions are used.
You can read more about exceptions here.
Hope this helps.