是否有任何优势或用例来抛出 std::exception( 或派生类型) 的其他东西。
例如throw 1;
或throw "error";
换句话说为什么 c++ 标准允许它。
最佳答案
根据 §15.1 [除外]:
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.
信息这个词说明了一切,它可以是任何事物,例如对象、数字……。
标准中没有任何内容规定您必须抛出 std::exception
。换句话说,也许有人想抛出他自己的异常对象。
也许有人想使用异常处理来处理一些与正常异常相去甚远的事情。
关于c++ - 抛出 std::exception( 或派生类型) 的其他东西有什么好处吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16794972/