这是 Stroustup 的书的摘录,第 3 版,第 362 页:
In principle, an exception is copied when it is thrown, so the handler gets hold of a copy of the original exception. In fact, an exception may be copied several times before it is caught. Consequently, we cannot throw an exception that cannot be copied. The implementation may apply a wide variety of strategies for storing and transmitting exceptions. It is guaranteed, however, that there is sufficient memory to allow new to throw the standard outofmemory exception, bad_alloc.
最佳答案
这意味着如果你用完内存并且调用 new() 抛出一个 std::bad_alloc,将保留一些内存来创建,并在没有的情况下制作正确数量的 std::bad_alloc 对象作为抛出异常的过程抛出另一个 std::bad_alloc。
关于c++ - 下面最后一句话(粗体)与复制抛出的异常有什么关系?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8943550/