这段程序会输出什么?

来自 RAII
C++23 (GCC 13.3.0) 进阶 2分钟

这段程序会输出什么?

C++
#include <iostream>
#include <stdexcept>

struct Guard {
    int id;
    Guard(int value) : id(value) { std::cout << "+" << id << '\n'; }
    ~Guard() { std::cout << "-" << id << '\n'; }
};

void run() {
    Guard first(1);
    Guard second(2);
    throw std::runtime_error("stop");
}

int main() {
    try { run(); }
    catch (const std::exception&) { std::cout << "caught\n"; }
}
在试验场中打开
报告错误