try
{
*(int *) 0 = 0; // generate structured exception
}
catch (unsigned exception)
{
cout << "caught c++ exception " << hex << exception << endl;
}
return 0;
}
再运行程序。现在将看到:
caught c++ exception c0000005
my_translator()截获了seh异常,并转换为c++异常,其类型为unsigned,内容为seh异常码(本例中为c0000005h,它是一个非法读取错误)。因为这个c++异常出现在原来的seh异常发生点,也就说在try块中,所以被try块的异常处理函数捕获了。
1.2 version 2:定义一个转换对象
上面的例子非常简单,将每个seh异常转换为一个unsigned值。实际上,你可能需要一个比较复杂的异常对象:
#include <iostream>
using namespace std;