请考虑以下代码:
#include <iostream>
#include <stdexcept>
void foo()
{
throw std::runtime_error("How long do I live?");
}
int main()
{
try
{
foo();
}
catch (std::runtime_error& e)
{
std::cout << e.what() << std::endl;
}
}
Run Code Online (Sandbox Code Playgroud)
为什么我可以通过引用捕获异常,不是std::runtime_error("How long do I live?")rvalue?
为什么异常对象在catch块中仍然存在?
究竟抛出异常对象存储在哪里?他们的一生是几岁?
是否存在operator new[]用作分配器的STL实现?在我的编译器上,Foo::operator new[]私有化并没有阻止我创建一个vector<Foo>......是什么行为保证了什么?