Creating custom exceptions in C++

后端 未结 3 920
陌清茗
陌清茗 2020-12-14 15:26

I am learning C++ and I am experiencing when I try and create my own exception and throw them on Linux.

I\'ve created a small test project to test my implementation

3条回答
  •  北海茫月
    2020-12-14 15:35

    Your what() returns:

     return exception::what();
    

    The return value from std::exception::what() is specified as follows:

    Pointer to a null-terminated string with explanatory information.

    That's it. Nothing more, nothing else. The text you're showing certainly qualifies as an "explanatory information". And this is the only requirement for the return value of what() (except for one other one which is not germane here).

    In other words, C++ does not guarantee the exact contents of what you get with what(). what() you see is what() you get, as the saying goes.

    If you want your exception to describe itself, in some way, it's up to you to implement that, as part of your what().

提交回复
热议问题