Is there any advantages to throw other thing that a std::exception( or derivatives types)

后端 未结 5 984
广开言路
广开言路 2021-01-21 02:25

Is there any advantages or uses cases to throw other thing that a std::exception( or a derivatives types).

For example throw 1; or throw \"error\";

5条回答
  •  别那么骄傲
    2021-01-21 02:56

    Per §15.1 [except]:

    Exception handling provides a way of transferring control and information from a point in the execution of a thread to an exception handler associated with a point previously passed by the execution.

    The word information illustrates everything, it can be everything such as objects, numbers, ... .

    There is nothing in standard that says you must just throw std::exception. In the other words, maybe someone wants to throw his own exception objects.

    Maybe someone wants to use exception-handling to handle something far from normal exceptions.

提交回复
热议问题