今日免费次数已满, 请开通会员/明日再来
#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;
}
}
为什么可以通过引用捕获异常,std::runtime_error("How long do I live?")
不是一个右值吗?
异常对象在catch块中如何仍然存活?
抛出的异常对象存储在哪里?它们的生命周期是什么?