0

为什么这个程序

#include <clang-c/Index.h>
#include <exception>
#include <iostream>

int main() {
    try {
        throw std::exception("threw");
    } catch (const std::exception& e) {
        std::cout << e.what() << "\n";
    }
    CXIndex idx = clang_createIndex(0, 0);
    clang_disposeIndex(idx);
    return 0;
}

表现如预期,但这一个

#include <clang-c/Index.h>
#include <exception>
#include <iostream>

int main() {
    CXIndex idx = clang_createIndex(0, 0);
    clang_disposeIndex(idx);
    try {
        throw std::exception("threw");
    } catch (const std::exception& e) {
        std::cout << e.what() << "\n";
    }
    return 0;
}

崩溃?

更一般地说,一个函数可以做什么来导致后续异常不被捕获?

使用:visual c++ 10.0(尝试了不同的 /EH 标志),clang 3.4(使用相同的构建)

4

0 回答 0