exit() call inside a function which should return a reference

前端 未结 4 1564
囚心锁ツ
囚心锁ツ 2020-11-27 08:13

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,

4条回答
  •  不知归路
    2020-11-27 08:57

    Exceptions

    This is a common situation in many programs. To overcome this, Exceptions are used.

    • To handle unexpected situations, new Exceptions are created and "thrown" from the code.
    • Then they have to be "caught" by the program calling the function.

    You can read more about exceptions here.

    Hope this helps.

提交回复
热议问题