Clang 对于C+,叮当声不能正常工作+;例外情况 structZeroError{ INTERR; 零错误(int e){err=e;} }; 内部分区(内部a、内部b) { 如果(b==0)抛出int(10); 返回a/b; } int main() { 试一试{ int x=div(10,0); 无法尝试使用-fcxx异常编译

Clang 对于C+,叮当声不能正常工作+;例外情况 structZeroError{ INTERR; 零错误(int e){err=e;} }; 内部分区(内部a、内部b) { 如果(b==0)抛出int(10); 返回a/b; } int main() { 试一试{ int x=div(10,0); 无法尝试使用-fcxx异常编译,clang,Clang,对代码进行了一点清理,使用div作为函数名,与stdlib.h中的函数名冲突。还尝试使错误输出更加独特 struct ZeroError{ int err; ZeroError(int e){err = e;} }; int div(int a,int b) { if (b == 0)throw int(10); return a/b; } int main() { try{ int x = div(10,0); c

对代码进行了一点清理,使用
div
作为函数名,与
stdlib.h
中的函数名冲突。还尝试使错误输出更加独特

struct ZeroError{
    int err;
    ZeroError(int e){err = e;}
};


int div(int a,int b)
{
    if (b == 0)throw int(10);
    return a/b;
}


int main()
{
    try{
        int x = div(10,0);
        cout<< x;
    }
    catch(int z){
        cout<<z;
    }

}

看起来像是用异常编译的,在Win32中支持异常的支持,但是,你如何打开CLAN中的C++异常?例如,在MSVC中,使用'/EHSC '。
#include <iostream>
#include <exception>
using namespace std;

struct ZeroError{
    int err;
    ZeroError(int e){err = e;}
};


int divide(int a,int b)
{
    if (b == 0)throw int(10);
    return a/b;
}


int main()
{
    try{
        int x = divide(10,0);
        cout << x << endl;
    }
    catch(int z){
        cout << "Exception: " << z << endl;
    }
}
% clang++ -fcxx-exceptions foo.cc
% ./a.out
Exception: 10

% clang++ --version
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.1.0
Thread model: posix